Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

feat: zones refactor #280

Merged
merged 13 commits into from
Oct 21, 2022
Merged

feat: zones refactor #280

merged 13 commits into from
Oct 21, 2022

Conversation

harrysolovay
Copy link
Contributor

@harrysolovay harrysolovay commented Oct 4, 2022

No description provided.

@harrysolovay harrysolovay changed the title feat: beginnings of zones refactor feat: zones refactor Oct 20, 2022
@harrysolovay harrysolovay marked this pull request as ready for review October 20, 2022 16:24
Comment on lines +38 to +41
if (rc() == 1) {
const close = await client.close();
if (close instanceof Error) return close;
}
Copy link
Contributor

@kratico kratico Oct 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a couple of console.log to RpcCall, rpcClient and example/watch_blocks and the output was

root@480c9297b2b1:/workspaces/capi# deno task run test_ctx.ts deno task run examples/watch_blocks.ts
Warning deno task is unstable and may drastically change in the future
Task run deno run -A --no-check=remote "test_ctx.ts" "deno" "task" "run" "examples/watch_blocks.ts"
Check file:///workspaces/capi/test_ctx.ts
Warning deno task is unstable and may drastically change in the future
Task run deno run -A --no-check=remote "examples/watch_blocks.ts"
Check file:///workspaces/capi/examples/watch_blocks.ts
rpc.stdClient
ws.onOpen
result
rpc.stdClient
ws.onOpen
result
rpc.stdClient
result
rpc.stdClient
ws.onOpen
closing..
ws.onOpen
close instanceof Error false
// block data and count ==  0
closing..
close instanceof Error false
// block data and count ==  1
closing..
close instanceof Error false
// block data and count ==  2
rpc.stdClient
ws.onOpen
closing..
close instanceof Error false

It seems that

  • rpc.stdClient(config) is invoked many times
  • as a result rc() == 1 is always true, that's why client.close() is invoked more than once

This would be the patch for above console.log entries

diff --git a/effect/RpcCall.ts b/effect/RpcCall.ts
index 8059e3a..465c8f5 100644
--- a/effect/RpcCall.ts
+++ b/effect/RpcCall.ts
@@ -36,7 +36,10 @@ export class RpcCall<
           });
         }
         if (rc() == 1) {
+          console.log("closing..");
           const close = await client.close();
+          console.log("close instanceof Error", close instanceof Error);
+          // console.log("result", result);
           if (close instanceof Error) return close;
         }
         // TODO: should this effect implicitly index into `result`?
diff --git a/effect/core/rpcClient.ts b/effect/core/rpcClient.ts
index 742e9f1..8a40f51 100644
--- a/effect/core/rpcClient.ts
+++ b/effect/core/rpcClient.ts
@@ -7,5 +7,6 @@ export function rpcClient<C extends Config>(config: C) {
 }
 
 function impl<C extends Config>(config: C) {
+  console.log("rpc.stdClient");
   return rpc.stdClient(config);
 }
diff --git a/examples/watch_blocks.ts b/examples/watch_blocks.ts
index 29ae6d1..ec8420c 100644
--- a/examples/watch_blocks.ts
+++ b/examples/watch_blocks.ts
@@ -4,7 +4,8 @@ import * as U from "../util/mod.ts";
 const root = new C.BlockWatch(C.polkadot, (stop) => {
   let i = 0;
   return ({ block }) => {
-    console.log(block.header);
+    // console.log(block.header);
+    console.log("// block data and count == ", i);
     if (i === 2) {
       stop();
     }
diff --git a/rpc/providers/proxy.ts b/rpc/providers/proxy.ts
index cfbb544..53ceb9c 100644
--- a/rpc/providers/proxy.ts
+++ b/rpc/providers/proxy.ts
@@ -22,6 +22,7 @@ export async function proxyClient<Config_ extends Config<string>>(
       pending.resolve(new FailedToOpenConnectionError());
     };
     const onOpen = () => {
+      console.log("ws.onOpen");
       clearListeners();
       pending.resolve(client);
     };
@@ -68,7 +69,7 @@ export class ProxyClient<Config_ extends Config>
           ws.addEventListener("close", onClose);
           ws.close();
           try {
-            await deadline(pending, 250);
+            await deadline(pending, 2500);
           } catch (_e) {
             pending.resolve(new FailedToDisconnectError());
           }

@kratico kratico self-requested a review October 20, 2022 20:03
kratico
kratico previously approved these changes Oct 20, 2022
Copy link
Contributor

@kratico kratico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix the examples in main

@harrysolovay harrysolovay merged commit 8f1ed25 into main Oct 21, 2022
@harrysolovay harrysolovay deleted the with-zones branch October 21, 2022 19:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants