knitting 0.1.56 → 0.1.60
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 +254 -40
- package/knitting.d.ts +3 -2
- package/knitting.js +3 -3
- package/map.md +21 -9
- package/package.json +7 -1
- package/scripts/build-compiled-worker.ts +276 -0
- package/scripts/compiled-worker/porffor.d.ts +5 -0
- package/scripts/compiled-worker/runtime.ts +529 -0
- package/scripts/compiled-worker/task-shim.ts +32 -0
- package/src/api.d.ts +24 -1
- package/src/api.js +199 -20
- package/src/common/module-url.d.ts +1 -0
- package/src/common/module-url.js +30 -2
- package/src/common/node-compat.d.ts +2 -0
- package/src/common/path-canonical.js +20 -6
- package/src/common/runtime.d.ts +2 -1
- package/src/common/runtime.js +18 -4
- package/src/common/task-source.d.ts +2 -0
- package/src/common/task-source.js +17 -1
- package/src/common/worker-runtime.js +16 -7
- package/src/connections/buffer-reference-native.js +25 -1
- package/src/connections/buffer-reference.d.ts +23 -2
- package/src/connections/buffer-reference.js +143 -29
- package/src/connections/bun.d.ts +1 -1
- package/src/connections/bun.js +25 -14
- package/src/connections/deno.d.ts +3 -1
- package/src/connections/deno.js +35 -14
- package/src/connections/external-array-buffer.d.ts +2 -0
- package/src/connections/external-array-buffer.js +33 -0
- package/src/connections/node-addons.d.ts +11 -0
- package/src/connections/node-addons.js +49 -1
- package/src/connections/node-ffi-api.d.ts +19 -0
- package/src/connections/node-ffi-api.js +28 -0
- package/src/connections/node-ffi.d.ts +27 -0
- package/src/connections/node-ffi.js +262 -0
- package/src/connections/node.d.ts +1 -1
- package/src/connections/node.js +20 -20
- package/src/connections/package-assets.js +25 -15
- package/src/connections/posix.d.ts +42 -0
- package/src/connections/posix.js +101 -0
- package/src/connections/process-shared-buffer.d.ts +1 -0
- package/src/connections/process-shared-buffer.js +11 -45
- package/src/connections/types.d.ts +4 -0
- package/src/connections/windows.d.ts +19 -10
- package/src/connections/windows.js +87 -66
- package/src/error.d.ts +7 -6
- package/src/error.js +8 -7
- package/src/memory/lock.d.ts +87 -77
- package/src/memory/lock.js +103 -84
- package/src/memory/payloadCodec.d.ts +11 -2
- package/src/memory/payloadCodec.js +127 -31
- package/src/permission/compatibility.d.ts +28 -0
- package/src/permission/compatibility.js +239 -0
- package/src/permission/index.d.ts +2 -0
- package/src/permission/index.js +1 -0
- package/src/permission/protocol.d.ts +1 -0
- package/src/permission/protocol.js +54 -14
- package/src/runtime/compiled-artifact.d.ts +21 -0
- package/src/runtime/compiled-artifact.js +260 -0
- package/src/runtime/compiled-builder.d.ts +8 -0
- package/src/runtime/compiled-builder.js +42 -0
- package/src/runtime/compiled-worker.d.ts +27 -0
- package/src/runtime/compiled-worker.js +562 -0
- package/src/runtime/inline-executor.js +27 -15
- package/src/runtime/pool.d.ts +7 -2
- package/src/runtime/pool.js +74 -6
- package/src/runtime/process-worker.d.ts +1 -1
- package/src/runtime/process-worker.js +48 -8
- package/src/runtime/tx-queue.d.ts +3 -1
- package/src/runtime/tx-queue.js +4 -1
- package/src/types.d.ts +48 -6
- package/src/worker/composable-runners.js +3 -2
- package/src/worker/loop.d.ts +1 -0
- package/src/worker/loop.js +25 -12
- package/src/worker/task-loader.d.ts +5 -4
- package/src/worker/task-loader.js +13 -7
- package/src/worker/timers.js +8 -6
|
@@ -9,10 +9,11 @@ type GetFunctionParams = {
|
|
|
9
9
|
permission?: ResolvedPermissionProtocol;
|
|
10
10
|
};
|
|
11
11
|
type WorkerCallable = (args: unknown, abortToolkit?: unknown) => unknown;
|
|
12
|
-
export declare const
|
|
13
|
-
Reject
|
|
14
|
-
Resolve
|
|
15
|
-
}
|
|
12
|
+
export declare const TimeoutKind: {
|
|
13
|
+
readonly Reject: 0;
|
|
14
|
+
readonly Resolve: 1;
|
|
15
|
+
};
|
|
16
|
+
export type TimeoutKind = typeof TimeoutKind[keyof typeof TimeoutKind];
|
|
16
17
|
export type TimeoutSpec = {
|
|
17
18
|
ms: number;
|
|
18
19
|
kind: TimeoutKind;
|
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
import { endpointSymbol } from "../common/task-symbol.js";
|
|
2
|
-
import { toModuleUrl } from "../common/module-url.js";
|
|
2
|
+
import { toImportSpecifier, toModuleUrl } from "../common/module-url.js";
|
|
3
|
+
// const object, not `const enum`: Andromeda's Nova engine can't parse `enum`.
|
|
4
|
+
// No longer inlined, but only read on cold paths.
|
|
5
|
+
export const TimeoutKind = {
|
|
6
|
+
Reject: 0,
|
|
7
|
+
Resolve: 1,
|
|
8
|
+
};
|
|
3
9
|
const normalizeTimeout = (timeout) => {
|
|
4
10
|
if (timeout == null)
|
|
5
11
|
return undefined;
|
|
6
12
|
if (typeof timeout === "number") {
|
|
7
13
|
const ms = Math.floor(timeout);
|
|
8
14
|
return ms >= 0
|
|
9
|
-
? { ms, kind:
|
|
15
|
+
? { ms, kind: TimeoutKind.Reject, value: new Error("Task timeout") }
|
|
10
16
|
: undefined;
|
|
11
17
|
}
|
|
12
18
|
const ms = Math.floor(timeout.time);
|
|
13
19
|
if (!(ms >= 0))
|
|
14
20
|
return undefined;
|
|
15
21
|
if ("default" in timeout) {
|
|
16
|
-
return { ms, kind:
|
|
22
|
+
return { ms, kind: TimeoutKind.Resolve, value: timeout.default };
|
|
17
23
|
}
|
|
18
24
|
if (timeout.maybe === true) {
|
|
19
|
-
return { ms, kind:
|
|
25
|
+
return { ms, kind: TimeoutKind.Resolve, value: undefined };
|
|
20
26
|
}
|
|
21
27
|
if ("error" in timeout) {
|
|
22
|
-
return { ms, kind:
|
|
28
|
+
return { ms, kind: TimeoutKind.Reject, value: timeout.error };
|
|
23
29
|
}
|
|
24
|
-
return { ms, kind:
|
|
30
|
+
return { ms, kind: TimeoutKind.Reject, value: new Error("Task timeout") };
|
|
25
31
|
};
|
|
26
32
|
const composeWorkerCallable = (fixed, _permission) => {
|
|
27
33
|
return fixed.f;
|
|
@@ -30,7 +36,7 @@ export const getFunctions = async ({ list, ids, names, at, permission }) => {
|
|
|
30
36
|
const modules = list.map((specifier) => toModuleUrl(specifier));
|
|
31
37
|
const nameSet = new Set(names);
|
|
32
38
|
const results = await Promise.all(modules.map(async (imports) => {
|
|
33
|
-
const module = (await import(imports));
|
|
39
|
+
const module = (await import(toImportSpecifier(imports)));
|
|
34
40
|
const fixedTasks = Object.entries(module)
|
|
35
41
|
.filter(([_, value]) => value != null && typeof value === "object" &&
|
|
36
42
|
//@ts-ignore Reason -> trust me
|
package/src/worker/timers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
1
|
+
// const object, not `enum`: Andromeda's Nova engine can't parse `enum`.
|
|
2
|
+
const Comment = {
|
|
3
|
+
thisIsAHint: 0,
|
|
4
|
+
};
|
|
5
5
|
const maybeGc = (() => {
|
|
6
6
|
const host = globalThis;
|
|
7
7
|
const gc = typeof host.gc === "function"
|
|
@@ -51,6 +51,7 @@ const isPlainNodeWindows = runtimeGlobals.process?.platform === "win32" &&
|
|
|
51
51
|
// runners appear to hang. The native wait already polls internally, so this is
|
|
52
52
|
// just bounding each poll slice.
|
|
53
53
|
const nativeWaitTimeoutMs = (parkMs) => isPlainNodeWindows ? 1 : Number.isFinite(parkMs) ? parkMs : Infinity;
|
|
54
|
+
const pollingWaitTimeoutMs = (parkMs) => Number.isFinite(parkMs) ? Math.min(Math.max(parkMs, 0), 1) : 1;
|
|
54
55
|
export const whilePausing = ({ pauseInNanoseconds }) => {
|
|
55
56
|
const forNanoseconds = pauseInNanoseconds ?? DEFAULT_PAUSE_TIME;
|
|
56
57
|
if (!a_pause || forNanoseconds <= 0)
|
|
@@ -108,8 +109,9 @@ export const sleepUntilChanged = ({ at, opView, pauseInNanoseconds, rxStatus, tx
|
|
|
108
109
|
}
|
|
109
110
|
else if (a_wait && waitFallbackView) {
|
|
110
111
|
// waitFallbackView is never notified — this wait only ever times out and
|
|
111
|
-
// re-polls
|
|
112
|
-
|
|
112
|
+
// re-polls. Keep the slice short and finite so FFI-backed process workers
|
|
113
|
+
// stay responsive without a cross-process native wake primitive.
|
|
114
|
+
a_wait(waitFallbackView, 0, 0, pollingWaitTimeoutMs(parkMs));
|
|
113
115
|
}
|
|
114
116
|
a_store(rxStatus, 0, 1);
|
|
115
117
|
};
|