@atolljs/node 0.1.1 → 0.1.3
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/LICENSE +21 -0
- package/README.md +10 -6
- package/package.json +5 -4
- package/src/redis.ts +7 -0
- package/src/sharedBuffer.ts +9 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Justin Henry
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
# @atolljs/node
|
|
2
2
|
|
|
3
|
+
[](https://github.com/jwhenry3/atolljs/actions/workflows/ci.yml)
|
|
4
|
+
[](https://codecov.io/gh/jwhenry3/atolljs)
|
|
5
|
+
[](https://badge.socket.dev/npm/package/@atolljs/node)
|
|
6
|
+
|
|
3
7
|
`node:worker_threads` runtime adapter for `@atolljs/core` — lets `WorkerPool`
|
|
4
8
|
and `connectWorker` run on Node's `Worker` (an `EventEmitter`) instead of the
|
|
5
9
|
DOM surface they expect. No framework required.
|
|
6
10
|
|
|
7
|
-
**[Atoll — package documentation](https://jwhenry3.github.io/atolljs/consumer
|
|
11
|
+
**[Atoll — package documentation](https://jwhenry3.github.io/atolljs/consumer/quickstart/)**
|
|
8
12
|
|
|
9
13
|
## Install
|
|
10
14
|
|
|
@@ -93,8 +97,8 @@ export const counterWorker = defineWorker({
|
|
|
93
97
|
|
|
94
98
|
## Documentation
|
|
95
99
|
|
|
96
|
-
- [Atoll — package documentation](https://jwhenry3.github.io/atolljs/consumer
|
|
97
|
-
- [Node backends — Express, Fastify, Hono, Koa](https://jwhenry3.github.io/atolljs/consumer
|
|
98
|
-
- [Worker HTTP servers — clustering & gateway](https://jwhenry3.github.io/atolljs/consumer
|
|
99
|
-
- [Worker pool & tasks](https://jwhenry3.github.io/atolljs/consumer
|
|
100
|
-
- [NestJS guide](https://jwhenry3.github.io/atolljs/consumer
|
|
100
|
+
- [Atoll — package documentation](https://jwhenry3.github.io/atolljs/consumer/quickstart/)
|
|
101
|
+
- [Node backends — Express, Fastify, Hono, Koa](https://jwhenry3.github.io/atolljs/consumer/fw-node/)
|
|
102
|
+
- [Worker HTTP servers — clustering & gateway](https://jwhenry3.github.io/atolljs/consumer/fw-node/clustering/)
|
|
103
|
+
- [Worker pool & tasks](https://jwhenry3.github.io/atolljs/consumer/tasks/)
|
|
104
|
+
- [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.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Node runtime adapter — node:worker_threads pools, no framework",
|
|
5
|
-
"homepage": "https://jwhenry3.github.io/atolljs/consumer
|
|
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.
|
|
21
|
+
"@atolljs/core": "0.1.3"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
@@ -27,5 +27,6 @@
|
|
|
27
27
|
},
|
|
28
28
|
"bugs": {
|
|
29
29
|
"url": "https://github.com/jwhenry3/atolljs/issues"
|
|
30
|
-
}
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT"
|
|
31
32
|
}
|
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
|
}
|
package/src/sharedBuffer.ts
CHANGED
|
@@ -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
|
|
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
|
}
|