Module
x/async_call_rpc/docs/async-call-rpc.asyncgeneratorcall.md
A lightweight JSON RPC client & server
Home > async-call-rpc > AsyncGeneratorCall
AsyncGeneratorCall() function
The async generator version of the AsyncCall
Signature:
export declare function AsyncGeneratorCall<OtherSideImplementedFunctions = {}>(thisSideImplementation: object | Promise<object> | undefined, options: AsyncCallOptions): _AsyncGeneratorVersionOf<OtherSideImplementedFunctions>;
Parameters
Parameter | Type | Description |
---|---|---|
thisSideImplementation | object | Promise<object> | undefined | The implementation when this AsyncCall acts as a JSON RPC server. |
options | AsyncCallOptions | AsyncCallOptions |
Returns:
_AsyncGeneratorVersionOf<OtherSideImplementedFunctions>
Remarks
To use AsyncGeneratorCall, the server and the client MUST support the following JSON RPC internal methods:
Warning: Due to technical limitation, AsyncGeneratorCall will leak memory before the ECMAScript WeakRef proposal shipped.
rpc.async-iterator.start
rpc.async-iterator.next
rpc.async-iterator.return
rpc.async-iterator.throw
Example
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)
}
}