A lightweight JSON RPC client & server

Home > async-call-rpc > AsyncGeneratorCall

AsyncGeneratorCall() function

The async generator version of the AsyncCall


export declare function AsyncGeneratorCall<OtherSideImplementedFunctions = {}>(thisSideImplementation: null | undefined | object | Promise<object>, options: AsyncCallOptions): _AsyncGeneratorVersionOf<OtherSideImplementedFunctions>;


Parameter Type Description
thisSideImplementation null | undefined | object | Promise<object> The implementation when this AsyncCall acts as a JSON RPC server.
options AsyncCallOptions AsyncCallOptions




Warning: Due to technical limitation, AsyncGeneratorCall will leak memory. Use it at your own risk.

To use AsyncGeneratorCall, the server and the client MUST support the following JSON RPC internal methods which is pre ECMAScript async generator semantics:


const server = {
     async *generator() {
         let last = 0
         while (true) yield last++
type Server = typeof server
const serverRPC = AsyncGeneratorCall<Server>({}, { channel })
async function main() {
     for await (const x of serverRPC.generator()) {
         console.log('Server yielded number', x)