@dxos/functions 0.5.5-main.23d7ea6 → 0.5.5-main.6a9d10e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/functions",
3
- "version": "0.5.5-main.23d7ea6",
3
+ "version": "0.5.5-main.6a9d10e",
4
4
  "description": "Functions API and runtime.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -49,23 +49,23 @@
49
49
  "express": "^4.19.2",
50
50
  "get-port-please": "^3.1.1",
51
51
  "ws": "^8.14.2",
52
- "@braneframe/types": "0.5.5-main.23d7ea6",
53
- "@dxos/client": "0.5.5-main.23d7ea6",
54
- "@dxos/async": "0.5.5-main.23d7ea6",
55
- "@dxos/echo-schema": "0.5.5-main.23d7ea6",
56
- "@dxos/context": "0.5.5-main.23d7ea6",
57
- "@dxos/echo-db": "0.5.5-main.23d7ea6",
58
- "@dxos/invariant": "0.5.5-main.23d7ea6",
59
- "@dxos/keys": "0.5.5-main.23d7ea6",
60
- "@dxos/log": "0.5.5-main.23d7ea6",
61
- "@dxos/protocols": "0.5.5-main.23d7ea6",
62
- "@dxos/node-std": "0.5.5-main.23d7ea6",
63
- "@dxos/util": "0.5.5-main.23d7ea6"
52
+ "@dxos/client": "0.5.5-main.6a9d10e",
53
+ "@dxos/async": "0.5.5-main.6a9d10e",
54
+ "@dxos/context": "0.5.5-main.6a9d10e",
55
+ "@dxos/echo-db": "0.5.5-main.6a9d10e",
56
+ "@dxos/echo-schema": "0.5.5-main.6a9d10e",
57
+ "@dxos/invariant": "0.5.5-main.6a9d10e",
58
+ "@dxos/keys": "0.5.5-main.6a9d10e",
59
+ "@dxos/log": "0.5.5-main.6a9d10e",
60
+ "@braneframe/types": "0.5.5-main.6a9d10e",
61
+ "@dxos/node-std": "0.5.5-main.6a9d10e",
62
+ "@dxos/protocols": "0.5.5-main.6a9d10e",
63
+ "@dxos/util": "0.5.5-main.6a9d10e"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@types/express": "^4.17.17",
67
67
  "@types/ws": "^7.4.0",
68
- "@dxos/agent": "0.5.5-main.23d7ea6"
68
+ "@dxos/agent": "0.5.5-main.6a9d10e"
69
69
  },
70
70
  "publishConfig": {
71
71
  "access": "public"
@@ -30,6 +30,7 @@ export const createWebsocketTrigger: TriggerFactory<WebsocketTrigger, WebsocketT
30
30
  ) => {
31
31
  const { url, init } = spec;
32
32
 
33
+ let wasOpen = false;
33
34
  let ws: WebSocket;
34
35
  for (let attempt = 1; attempt <= options.maxAttempts; attempt++) {
35
36
  const open = new Trigger<boolean>();
@@ -49,18 +50,18 @@ export const createWebsocketTrigger: TriggerFactory<WebsocketTrigger, WebsocketT
49
50
  log.info('closed', { url, code: event.code });
50
51
  // Reconnect if server closes (e.g., CF restart).
51
52
  // https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
52
- if (event.code === 1006) {
53
+ if (event.code === 1006 && wasOpen && !ctx.disposed) {
53
54
  setTimeout(async () => {
54
55
  log.info(`reconnecting in ${options.retryDelay}s...`, { url });
55
56
  await createWebsocketTrigger(ctx, space, spec, callback, options);
56
57
  }, options.retryDelay * 1_000);
57
58
  }
58
-
59
59
  open.wake(false);
60
60
  },
61
61
 
62
62
  onerror: (event) => {
63
63
  log.catch(event.error, { url });
64
+ open.wake(false);
64
65
  },
65
66
 
66
67
  onmessage: async (event) => {
@@ -75,14 +76,17 @@ export const createWebsocketTrigger: TriggerFactory<WebsocketTrigger, WebsocketT
75
76
  } satisfies Partial<WebSocket>);
76
77
 
77
78
  const isOpen = await open.wait();
79
+ if (ctx.disposed) {
80
+ break;
81
+ }
78
82
  if (isOpen) {
83
+ wasOpen = true;
79
84
  break;
80
- } else {
81
- const wait = Math.pow(attempt, 2) * options.retryDelay;
82
- if (attempt < options.maxAttempts) {
83
- log.warn(`failed to connect; trying again in ${wait}s`, { attempt });
84
- await sleep(wait * 1_000);
85
- }
85
+ }
86
+ const wait = Math.pow(attempt, 2) * options.retryDelay;
87
+ if (attempt < options.maxAttempts) {
88
+ log.warn(`failed to connect; trying again in ${wait}s`, { attempt });
89
+ await sleep(wait * 1_000);
86
90
  }
87
91
  }
88
92