A lightweight JSON RPC client & server
Home > async-call-rpc > AsyncGeneratorCall
The async generator version of the AsyncCall
Signature:
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 |
Returns:
AsyncGeneratorVersionOf<OtherSideImplementedFunctions>
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:
rpc.async-iterator.start
rpc.async-iterator.next
rpc.async-iterator.return
rpc.async-iterator.throw
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)
}
}