@ricsam/isolate 0.1.5 → 0.1.6
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 +26 -6
- package/dist/cjs/internal/async-context/index.cjs +269 -8
- package/dist/cjs/internal/async-context/index.cjs.map +3 -3
- package/dist/cjs/internal/core/index.cjs +12 -4
- package/dist/cjs/internal/core/index.cjs.map +3 -3
- package/dist/cjs/internal/fetch/index.cjs +52 -13
- package/dist/cjs/internal/fetch/index.cjs.map +3 -3
- package/dist/cjs/internal/module-loader/bundle.cjs +111 -35
- package/dist/cjs/internal/module-loader/bundle.cjs.map +3 -3
- package/dist/cjs/internal/runtime/index.cjs +2 -2
- package/dist/cjs/internal/runtime/index.cjs.map +2 -2
- package/dist/cjs/internal/timers/index.cjs +39 -9
- package/dist/cjs/internal/timers/index.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/internal/async-context/index.mjs +269 -8
- package/dist/mjs/internal/async-context/index.mjs.map +3 -3
- package/dist/mjs/internal/core/index.mjs +12 -4
- package/dist/mjs/internal/core/index.mjs.map +3 -3
- package/dist/mjs/internal/fetch/index.mjs +52 -13
- package/dist/mjs/internal/fetch/index.mjs.map +3 -3
- package/dist/mjs/internal/module-loader/bundle.mjs +111 -35
- package/dist/mjs/internal/module-loader/bundle.mjs.map +3 -3
- package/dist/mjs/internal/runtime/index.mjs +2 -2
- package/dist/mjs/internal/runtime/index.mjs.map +2 -2
- package/dist/mjs/internal/timers/index.mjs +39 -9
- package/dist/mjs/internal/timers/index.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/package.json +2 -2
|
@@ -1911,11 +1911,16 @@ function setupClientWebSocket(context, clientWsCommandCallbacks) {
|
|
|
1911
1911
|
}
|
|
1912
1912
|
};
|
|
1913
1913
|
|
|
1914
|
-
const __wrapAsyncContextCallback = (callback) => (
|
|
1915
|
-
typeof callback === 'function' && globalThis.
|
|
1916
|
-
? globalThis.
|
|
1914
|
+
const __wrapAsyncContextCallback = (callback, options = {}) => (
|
|
1915
|
+
typeof callback === 'function' && globalThis.__isolateAsyncContextInternals?.wrapCallback
|
|
1916
|
+
? globalThis.__isolateAsyncContextInternals.wrapCallback(callback, options)
|
|
1917
1917
|
: callback
|
|
1918
1918
|
);
|
|
1919
|
+
const __releaseAsyncContextCallback = (callback) => (
|
|
1920
|
+
typeof callback === 'function' && globalThis.__isolateAsyncContextInternals?.releaseCallback
|
|
1921
|
+
? globalThis.__isolateAsyncContextInternals.releaseCallback(callback)
|
|
1922
|
+
: false
|
|
1923
|
+
);
|
|
1919
1924
|
|
|
1920
1925
|
// Helper to dispatch events
|
|
1921
1926
|
function dispatchEvent(ws, event) {
|
|
@@ -2052,13 +2057,20 @@ function setupClientWebSocket(context, clientWsCommandCallbacks) {
|
|
|
2052
2057
|
get CLOSED() { return WebSocket.CLOSED; }
|
|
2053
2058
|
|
|
2054
2059
|
_setHandler(type, handler) {
|
|
2060
|
+
const previous = this._handlers.get(type);
|
|
2061
|
+
if (previous?.wrapped) {
|
|
2062
|
+
__releaseAsyncContextCallback(previous.wrapped);
|
|
2063
|
+
}
|
|
2055
2064
|
if (typeof handler !== 'function') {
|
|
2056
2065
|
this._handlers.set(type, null);
|
|
2057
2066
|
return;
|
|
2058
2067
|
}
|
|
2059
2068
|
this._handlers.set(type, {
|
|
2060
2069
|
original: handler,
|
|
2061
|
-
wrapped: __wrapAsyncContextCallback(handler
|
|
2070
|
+
wrapped: __wrapAsyncContextCallback(handler, {
|
|
2071
|
+
resource: this,
|
|
2072
|
+
type: 'isolate.websocket',
|
|
2073
|
+
}),
|
|
2062
2074
|
});
|
|
2063
2075
|
}
|
|
2064
2076
|
|
|
@@ -2138,7 +2150,10 @@ function setupClientWebSocket(context, clientWsCommandCallbacks) {
|
|
|
2138
2150
|
if (!listeners.some((entry) => entry.original === listener)) {
|
|
2139
2151
|
listeners.push({
|
|
2140
2152
|
original: listener,
|
|
2141
|
-
wrapped: __wrapAsyncContextCallback(listener
|
|
2153
|
+
wrapped: __wrapAsyncContextCallback(listener, {
|
|
2154
|
+
resource: this,
|
|
2155
|
+
type: 'isolate.websocket',
|
|
2156
|
+
}),
|
|
2142
2157
|
});
|
|
2143
2158
|
}
|
|
2144
2159
|
}
|
|
@@ -2148,6 +2163,7 @@ function setupClientWebSocket(context, clientWsCommandCallbacks) {
|
|
|
2148
2163
|
if (!listeners) return;
|
|
2149
2164
|
const index = listeners.findIndex((entry) => entry.original === listener || entry.wrapped === listener);
|
|
2150
2165
|
if (index !== -1) {
|
|
2166
|
+
__releaseAsyncContextCallback(listeners[index].wrapped);
|
|
2151
2167
|
listeners.splice(index, 1);
|
|
2152
2168
|
}
|
|
2153
2169
|
}
|
|
@@ -2206,6 +2222,18 @@ function setupClientWebSocket(context, clientWsCommandCallbacks) {
|
|
|
2206
2222
|
this.#readyState = WebSocket.CLOSED;
|
|
2207
2223
|
const event = new _CloseEvent('close', { code, reason, wasClean });
|
|
2208
2224
|
dispatchEvent(this, event);
|
|
2225
|
+
for (const handler of this._handlers.values()) {
|
|
2226
|
+
if (handler?.wrapped) {
|
|
2227
|
+
__releaseAsyncContextCallback(handler.wrapped);
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
for (const listeners of this._listeners.values()) {
|
|
2231
|
+
for (const listener of listeners) {
|
|
2232
|
+
__releaseAsyncContextCallback(listener.wrapped);
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
this._handlers.clear();
|
|
2236
|
+
this._listeners.clear();
|
|
2209
2237
|
__clientWebSockets.delete(this.#socketId);
|
|
2210
2238
|
}
|
|
2211
2239
|
}
|
|
@@ -2241,9 +2269,9 @@ function setupServe(context) {
|
|
|
2241
2269
|
context.evalSync(`
|
|
2242
2270
|
(function() {
|
|
2243
2271
|
globalThis.__serveOptions__ = null;
|
|
2244
|
-
const __wrapAsyncContextCallback = (callback) => (
|
|
2245
|
-
typeof callback === 'function' && globalThis.
|
|
2246
|
-
? globalThis.
|
|
2272
|
+
const __wrapAsyncContextCallback = (callback, options = {}) => (
|
|
2273
|
+
typeof callback === 'function' && globalThis.__isolateAsyncContextInternals?.wrapCallback
|
|
2274
|
+
? globalThis.__isolateAsyncContextInternals.wrapCallback(callback, options)
|
|
2247
2275
|
: callback
|
|
2248
2276
|
);
|
|
2249
2277
|
|
|
@@ -2254,14 +2282,19 @@ function setupServe(context) {
|
|
|
2254
2282
|
|
|
2255
2283
|
const wrapped = { ...options };
|
|
2256
2284
|
if (typeof options.fetch === 'function') {
|
|
2257
|
-
wrapped.fetch = __wrapAsyncContextCallback(options.fetch
|
|
2285
|
+
wrapped.fetch = __wrapAsyncContextCallback(options.fetch, {
|
|
2286
|
+
type: 'isolate.serve',
|
|
2287
|
+
});
|
|
2258
2288
|
}
|
|
2259
2289
|
|
|
2260
2290
|
if (options.websocket && typeof options.websocket === 'object') {
|
|
2261
2291
|
wrapped.websocket = { ...options.websocket };
|
|
2262
2292
|
for (const name of ['open', 'message', 'close', 'error']) {
|
|
2263
2293
|
if (typeof options.websocket[name] === 'function') {
|
|
2264
|
-
wrapped.websocket[name] = __wrapAsyncContextCallback(
|
|
2294
|
+
wrapped.websocket[name] = __wrapAsyncContextCallback(
|
|
2295
|
+
options.websocket[name],
|
|
2296
|
+
{ type: 'isolate.serve.websocket' },
|
|
2297
|
+
);
|
|
2265
2298
|
}
|
|
2266
2299
|
}
|
|
2267
2300
|
}
|
|
@@ -2309,10 +2342,15 @@ async function setupFetch(context, options) {
|
|
|
2309
2342
|
(function() {
|
|
2310
2343
|
const __eventListeners = new Map();
|
|
2311
2344
|
const __wrapAsyncContextCallback = (callback) => (
|
|
2312
|
-
typeof callback === 'function' && globalThis.
|
|
2313
|
-
? globalThis.
|
|
2345
|
+
typeof callback === 'function' && globalThis.__isolateAsyncContextInternals?.wrapCallback
|
|
2346
|
+
? globalThis.__isolateAsyncContextInternals.wrapCallback(callback, { type: 'isolate.event' })
|
|
2314
2347
|
: callback
|
|
2315
2348
|
);
|
|
2349
|
+
const __releaseAsyncContextCallback = (callback) => (
|
|
2350
|
+
typeof callback === 'function' && globalThis.__isolateAsyncContextInternals?.releaseCallback
|
|
2351
|
+
? globalThis.__isolateAsyncContextInternals.releaseCallback(callback)
|
|
2352
|
+
: false
|
|
2353
|
+
);
|
|
2316
2354
|
|
|
2317
2355
|
globalThis.__on = function(event, callback) {
|
|
2318
2356
|
let listeners = __eventListeners.get(event);
|
|
@@ -2324,6 +2362,7 @@ async function setupFetch(context, options) {
|
|
|
2324
2362
|
listeners.add(wrapped);
|
|
2325
2363
|
return function() {
|
|
2326
2364
|
listeners.delete(wrapped);
|
|
2365
|
+
__releaseAsyncContextCallback(wrapped);
|
|
2327
2366
|
if (listeners.size === 0) {
|
|
2328
2367
|
__eventListeners.delete(event);
|
|
2329
2368
|
}
|
|
@@ -2699,4 +2738,4 @@ async function setupFetch(context, options) {
|
|
|
2699
2738
|
};
|
|
2700
2739
|
}
|
|
2701
2740
|
|
|
2702
|
-
//# debugId=
|
|
2741
|
+
//# debugId=9AF8B200C8CF0CEC64756E2164756E21
|