From 15502168ae1480c2bfd46352dbe8aaef8a90ca86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Sat, 10 Aug 2024 16:51:21 +1200 Subject: [PATCH] chore: update demos to use JSON-RPC responses async iterator --- wasm-node/javascript/demo/demo-deno.ts | 3 +-- wasm-node/javascript/demo/demo.mjs | 6 ++---- wasm-node/javascript/src/public-types.ts | 3 +-- wasm-node/javascript/tsconfig.json | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/wasm-node/javascript/demo/demo-deno.ts b/wasm-node/javascript/demo/demo-deno.ts index 8e3d68876f..c0b80d7508 100644 --- a/wasm-node/javascript/demo/demo-deno.ts +++ b/wasm-node/javascript/demo/demo-deno.ts @@ -69,8 +69,7 @@ while(true) { (async () => { try { - while(true) { - const response = await chain.nextJsonRpcResponse(); + for await (const response of chain.jsonRpcResponses) { socket.send(response); } } catch(_error) {} diff --git a/wasm-node/javascript/demo/demo.mjs b/wasm-node/javascript/demo/demo.mjs index f534d06ea1..e82598ba12 100644 --- a/wasm-node/javascript/demo/demo.mjs +++ b/wasm-node/javascript/demo/demo.mjs @@ -162,8 +162,7 @@ wsServer.on('connection', function (connection, request) { (async () => { try { - while(true) { - const response = await para.nextJsonRpcResponse(); + for await (const response of para.jsonRpcResponses) { connection.send(response); } } catch(_error) {} @@ -177,8 +176,7 @@ wsServer.on('connection', function (connection, request) { (async () => { try { - while(true) { - const response = await relay.nextJsonRpcResponse(); + for await (const response of relay.jsonRpcResponses) { connection.send(response); } } catch(_error) {} diff --git a/wasm-node/javascript/src/public-types.ts b/wasm-node/javascript/src/public-types.ts index e90f7ab30a..9cafae44d9 100644 --- a/wasm-node/javascript/src/public-types.ts +++ b/wasm-node/javascript/src/public-types.ts @@ -179,8 +179,7 @@ export interface Chain { /** * JSON-RPC responses or notifications to be generated. - * - * @throws {@link AlreadyDestroyedError} If the chain has been removed or the client has been terminated. + * * @throws {@link JsonRpcDisabledError} If the JSON-RPC system was disabled in the options of the chain. * @throws {@link CrashError} If the background client has crashed. */ diff --git a/wasm-node/javascript/tsconfig.json b/wasm-node/javascript/tsconfig.json index 786ce11661..600c863e45 100644 --- a/wasm-node/javascript/tsconfig.json +++ b/wasm-node/javascript/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "lib": ["ESNext"], + "target": "ES6", "declaration": true, "strict": true, "allowUnreachableCode": false,