A lightweight JSON RPC client & server
Home > async-call-rpc > AsyncCall
Create a RPC server & client.
Signature:
export declare function AsyncCall<OtherSideImplementedFunctions = {}>(thisSideImplementation: null | undefined | object | Promise<object>, options: AsyncCallOptions): AsyncVersionOf<OtherSideImplementedFunctions>;
Parameter | Type | Description |
---|---|---|
thisSideImplementation | null | undefined | object | Promise<object> | The implementation when this AsyncCall acts as a JSON RPC server. Can be a Promise. |
options | AsyncCallOptions | AsyncCallOptions |
Returns:
AsyncVersionOf<OtherSideImplementedFunctions>
Same as the OtherSideImplementedFunctions
type parameter, but every function in that interface becomes async and non-function value is removed. Method called “then” are also removed.
See AsyncCallOptions
thisSideImplementation can be a Promise so you can write:
export const service = AsyncCall(typeof window === 'object' ? {} : import('./backend/service.js'), {})