@atolljs/node 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  and `connectWorker` run on Node's `Worker` (an `EventEmitter`) instead of the
5
5
  DOM surface they expect. No framework required.
6
6
 
7
- **[Atoll — package documentation](https://jwhenry3.github.io/atolljs/consumer/#/quickstart)**
7
+ **[Atoll — package documentation](https://jwhenry3.github.io/atolljs/consumer/quickstart/)**
8
8
 
9
9
  ## Install
10
10
 
@@ -93,8 +93,8 @@ export const counterWorker = defineWorker({
93
93
 
94
94
  ## Documentation
95
95
 
96
- - [Atoll — package documentation](https://jwhenry3.github.io/atolljs/consumer/#/quickstart)
97
- - [Node backends — Express, Fastify, Hono, Koa](https://jwhenry3.github.io/atolljs/consumer/#/fw-node)
98
- - [Worker HTTP servers — clustering & gateway](https://jwhenry3.github.io/atolljs/consumer/#/fw-node/clustering)
99
- - [Worker pool & tasks](https://jwhenry3.github.io/atolljs/consumer/#/tasks)
100
- - [NestJS guide](https://jwhenry3.github.io/atolljs/consumer/#/fw-nestjs)
96
+ - [Atoll — package documentation](https://jwhenry3.github.io/atolljs/consumer/quickstart/)
97
+ - [Node backends — Express, Fastify, Hono, Koa](https://jwhenry3.github.io/atolljs/consumer/fw-node/)
98
+ - [Worker HTTP servers — clustering & gateway](https://jwhenry3.github.io/atolljs/consumer/fw-node/clustering/)
99
+ - [Worker pool & tasks](https://jwhenry3.github.io/atolljs/consumer/tasks/)
100
+ - [NestJS guide](https://jwhenry3.github.io/atolljs/consumer/fw-nestjs/)
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@atolljs/node",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Node runtime adapter — node:worker_threads pools, no framework",
5
- "homepage": "https://jwhenry3.github.io/atolljs/consumer/#/quickstart",
5
+ "homepage": "https://jwhenry3.github.io/atolljs/consumer/quickstart/",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": "./src/index.ts",
@@ -18,7 +18,7 @@
18
18
  "registry": "https://registry.npmjs.org"
19
19
  },
20
20
  "peerDependencies": {
21
- "@atolljs/core": "0.1.1"
21
+ "@atolljs/core": "0.1.2"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",
package/src/redis.ts CHANGED
@@ -205,6 +205,9 @@ export function persistSharedMemory<S extends SharedSpec>(
205
205
  }
206
206
  });
207
207
  }
208
+ // stop() may have run before ready resolved — don't start a poll
209
+ // loop that nothing will ever clear.
210
+ if (stopped) return;
208
211
  timer = setInterval(() => {
209
212
  flushing = flushing.then(flush).catch((e) => {
210
213
  log.warn('flush failed', e);
@@ -228,9 +231,13 @@ export function persistSharedMemory<S extends SharedSpec>(
228
231
  await subscriber?.unsubscribe?.(channel);
229
232
  await flushing.catch(() => 0);
230
233
  // One last flush — durability on shutdown — bypass the stopped guard.
234
+ // A Redis outage here must not reject stop(): teardown is done either
235
+ // way, the flush is best-effort persistence.
231
236
  stopped = false;
232
237
  try {
233
238
  await flush();
239
+ } catch (e) {
240
+ log.warn('final flush failed', e);
234
241
  } finally {
235
242
  stopped = true;
236
243
  }
@@ -58,19 +58,22 @@ export function bindSharedBuffer(timeoutMs = 10_000): Promise<SharedArrayBuffer>
58
58
  }
59
59
  const port = parentPort;
60
60
  return new Promise((resolve, reject) => {
61
- const timer = setTimeout(
62
- () => reject(new Error(`bindSharedBuffer(): no shared buffer arrived within ${timeoutMs}ms`)),
63
- timeoutMs,
64
- );
65
- port.on('message', (msg: { type?: string; buffer?: SharedArrayBuffer }) => {
61
+ const onMessage = (msg: { type?: string; buffer?: SharedArrayBuffer }) => {
66
62
  if (msg?.type !== SHARED_BUFFER) return;
67
63
  clearTimeout(timer);
64
+ port.off('message', onMessage);
68
65
  if (!msg.buffer) {
69
66
  reject(new Error('bindSharedBuffer(): the producing side sent an empty buffer'));
70
67
  return;
71
68
  }
72
69
  bindSharedMemories(msg.buffer);
73
70
  resolve(msg.buffer);
74
- });
71
+ };
72
+ const timer = setTimeout(() => {
73
+ // Detach — a late SHARED_BUFFER must not bind after the rejection.
74
+ port.off('message', onMessage);
75
+ reject(new Error(`bindSharedBuffer(): no shared buffer arrived within ${timeoutMs}ms`));
76
+ }, timeoutMs);
77
+ port.on('message', onMessage);
75
78
  });
76
79
  }