@xylabs/threads
Advanced tools
Comparing version 3.5.1 to 3.5.2
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.serialize = exports.deserialize = exports.registerSerializer = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
exports.registerSerializer = registerSerializer; | ||
exports.deserialize = deserialize; | ||
exports.serialize = serialize; | ||
const serializers_1 = require("./serializers"); | ||
@@ -10,10 +11,7 @@ let registeredSerializer = serializers_1.DefaultSerializer; | ||
} | ||
exports.registerSerializer = registerSerializer; | ||
function deserialize(message) { | ||
return registeredSerializer.deserialize(message); | ||
} | ||
exports.deserialize = deserialize; | ||
function serialize(input) { | ||
return registeredSerializer.serialize(input); | ||
} | ||
exports.serialize = serialize; |
@@ -18,3 +18,2 @@ "use strict"; | ||
exports.expose = exports.Transfer = exports.DefaultSerializer = exports.registerSerializer = void 0; | ||
/* eslint-disable import/no-internal-modules */ | ||
var common_1 = require("./common"); | ||
@@ -21,0 +20,0 @@ Object.defineProperty(exports, "registerSerializer", { enumerable: true, get: function () { return common_1.registerSerializer; } }); |
"use strict"; | ||
// Source: <https://github.com/parcel-bundler/parcel/blob/master/packages/core/parcel-bundler/src/builtins/bundle-url.js> | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getBundleURL = exports.getBaseURL = void 0; | ||
exports.getBaseURL = getBaseURL; | ||
exports.getBundleURL = getBundleURLCached; | ||
let bundleURL; | ||
@@ -12,5 +12,3 @@ function getBundleURLCached() { | ||
} | ||
exports.getBundleURL = getBundleURLCached; | ||
function getBundleURL() { | ||
// Attempt to find the URL of the current script and use that as the base URL | ||
try { | ||
@@ -30,2 +28,1 @@ throw new Error('getBundleURL failed'); | ||
} | ||
exports.getBaseURL = getBaseURL; |
"use strict"; | ||
// tslint:disable max-classes-per-file | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isWorkerRuntime = exports.getWorkerImplementation = exports.defaultPoolSize = void 0; | ||
exports.defaultPoolSize = void 0; | ||
exports.getWorkerImplementation = getWorkerImplementation; | ||
exports.isWorkerRuntime = isWorkerRuntime; | ||
const get_bundle_url_browser_1 = require("./get-bundle-url.browser"); | ||
@@ -14,4 +15,2 @@ exports.defaultPoolSize = typeof navigator !== 'undefined' && navigator.hardwareConcurrency ? navigator.hardwareConcurrency : 4; | ||
if (typeof Worker === 'undefined') { | ||
// Might happen on Safari, for instance | ||
// The idea is to only fail if the constructor is actually used | ||
return class NoWebWorker { | ||
@@ -35,4 +34,3 @@ constructor() { | ||
if (typeof url === 'string' && | ||
isAbsoluteURL(url) && // Create source code blob loading JS file via `importScripts()` | ||
// to circumvent worker CORS restrictions | ||
isAbsoluteURL(url) && | ||
(options?.CORSWorkaround ?? true)) { | ||
@@ -66,3 +64,2 @@ url = createSourceBlobURL(`importScripts(${JSON.stringify(url)});`); | ||
} | ||
exports.getWorkerImplementation = getWorkerImplementation; | ||
function isWorkerRuntime() { | ||
@@ -72,2 +69,1 @@ const isWindowContext = typeof self !== 'undefined' && typeof Window !== 'undefined' && self instanceof Window; | ||
} | ||
exports.isWorkerRuntime = isWorkerRuntime; |
import * as BrowserImplementation from './implementation.browser'; | ||
/** Default size of pools. Depending on the platform the value might vary from device to device. */ | ||
export declare const defaultPoolSize: number; | ||
export declare const getWorkerImplementation: typeof BrowserImplementation.getWorkerImplementation; | ||
/** Returns `true` if this code is currently running in a worker. */ | ||
export declare const isWorkerRuntime: typeof BrowserImplementation.isWorkerRuntime; |
"use strict"; | ||
/* | ||
* This file is only a stub to make './implementation' resolve to the right module. | ||
*/ | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
@@ -30,5 +27,2 @@ if (k2 === undefined) k2 = k; | ||
exports.isWorkerRuntime = exports.getWorkerImplementation = exports.defaultPoolSize = void 0; | ||
// We alias `src/master/implementation` to `src/master/implementation.browser` for web | ||
// browsers already in the package.json, so if get here, it's safe to pass-through the | ||
// node implementation | ||
const BrowserImplementation = __importStar(require("./implementation.browser")); | ||
@@ -38,6 +32,4 @@ const NodeImplementation = __importStar(require("./implementation.node")); | ||
const implementation = runningInNode ? NodeImplementation : BrowserImplementation; | ||
/** Default size of pools. Depending on the platform the value might vary from device to device. */ | ||
exports.defaultPoolSize = implementation.defaultPoolSize; | ||
exports.getWorkerImplementation = implementation.getWorkerImplementation; | ||
/** Returns `true` if this code is currently running in a worker. */ | ||
exports.isWorkerRuntime = implementation.isWorkerRuntime; |
@@ -1,2 +0,1 @@ | ||
/// <reference lib="dom" /> | ||
import { ImplementationExport } from '../types/master'; | ||
@@ -3,0 +2,0 @@ export declare const defaultPoolSize: number; |
"use strict"; | ||
/* eslint-disable unicorn/prefer-logical-operator-over-ternary */ | ||
/* eslint-disable unicorn/prefer-regexp-test */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
/* eslint-disable unicorn/prefer-add-event-listener */ | ||
/* eslint-disable unicorn/prefer-event-target */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable unicorn/text-encoding-identifier-case */ | ||
/* eslint-disable unicorn/no-process-exit */ | ||
/// <reference lib="dom" /> | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -15,3 +6,5 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isWorkerRuntime = exports.getWorkerImplementation = exports.defaultPoolSize = void 0; | ||
exports.defaultPoolSize = void 0; | ||
exports.getWorkerImplementation = getWorkerImplementation; | ||
exports.isWorkerRuntime = isWorkerRuntime; | ||
const node_events_1 = require("node:events"); | ||
@@ -26,3 +19,2 @@ const node_os_1 = require("node:os"); | ||
if (typeof __non_webpack_require__ === 'function') { | ||
// Webpack build: => No ts-node required or possible | ||
return false; | ||
@@ -42,3 +34,2 @@ } | ||
else { | ||
// Re-throw | ||
throw error; | ||
@@ -71,3 +62,2 @@ } | ||
const makeRelative = (filePath) => { | ||
// eval() hack is also webpack-related | ||
return node_path_1.default.isAbsolute(filePath) ? filePath : node_path_1.default.join(baseURL || eval('__dirname'), filePath); | ||
@@ -81,3 +71,2 @@ }; | ||
function initWorkerThreadsWorker() { | ||
// Webpack hack | ||
const NativeWorker = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__('worker_threads').Worker : eval('require')('worker_threads').Worker; | ||
@@ -90,3 +79,2 @@ let allWorkers = []; | ||
if (!resolvedScriptPath) { | ||
// `options.fromSource` is true | ||
const sourceCode = scriptPath; | ||
@@ -99,3 +87,2 @@ super(sourceCode, { ...options, eval: true }); | ||
else if (/\.asar[/\\]/.test(resolvedScriptPath)) { | ||
// See <https://github.com/andywer/threads-plugin/issues/17> | ||
super(resolvedScriptPath.replace(/\.asar([/\\])/, '.asar.unpacked$1'), options); | ||
@@ -122,7 +109,5 @@ } | ||
const terminateWorkersAndMaster = () => { | ||
// we should terminate all workers and then gracefully shutdown self process | ||
Promise.all(allWorkers.map((worker) => worker.terminate())).then(() => process.exit(0), () => process.exit(1)); | ||
allWorkers = []; | ||
}; | ||
// Take care to not leave orphaned processes behind. See #147. | ||
process.on('SIGINT', () => terminateWorkersAndMaster()); | ||
@@ -149,4 +134,2 @@ process.on('SIGTERM', () => terminateWorkersAndMaster()); | ||
constructor(scriptPath, options) { | ||
// Need to apply a work-around for Windows or it will choke upon the absolute path | ||
// (`Error [ERR_INVALID_PROTOCOL]: Protocol 'c:' not supported`) | ||
const resolvedScriptPath = options && options.fromSource ? null | ||
@@ -156,3 +139,2 @@ : process.platform === 'win32' ? `file:///${resolveScriptPath(scriptPath).replaceAll('\\', '/')}` | ||
if (!resolvedScriptPath) { | ||
// `options.fromSource` is true | ||
const sourceCode = scriptPath; | ||
@@ -165,3 +147,2 @@ super(new Function(sourceCode), [], { esm: true }); | ||
else if (/\.asar[/\\]/.test(resolvedScriptPath)) { | ||
// See <https://github.com/andywer/threads-plugin/issues/17> | ||
super(resolvedScriptPath.replace(/\.asar([/\\])/, '.asar.unpacked$1'), [], { esm: true }); | ||
@@ -189,8 +170,5 @@ } | ||
const terminateWorkersAndMaster = () => { | ||
// we should terminate all workers and then gracefully shutdown self process | ||
Promise.all(allWorkers.map((worker) => worker.terminate())).then(() => process.exit(0), () => process.exit(1)); | ||
allWorkers = []; | ||
}; | ||
// Take care to not leave orphaned processes behind | ||
// See <https://github.com/avoidwork/tiny-worker#faq> | ||
process.on('SIGINT', () => terminateWorkersAndMaster()); | ||
@@ -219,3 +197,2 @@ process.on('SIGTERM', () => terminateWorkersAndMaster()); | ||
catch { | ||
// tslint:disable-next-line no-console | ||
console.debug('Node worker_threads not available. Trying to fall back to tiny-worker polyfill...'); | ||
@@ -232,3 +209,2 @@ isTinyWorker = true; | ||
} | ||
exports.getWorkerImplementation = getWorkerImplementation; | ||
function isWorkerRuntime() { | ||
@@ -239,3 +215,2 @@ if (isTinyWorker) { | ||
else { | ||
// Webpack hack | ||
const isMainThread = typeof __non_webpack_require__ === 'function' ? | ||
@@ -247,2 +222,1 @@ __non_webpack_require__('worker_threads').isMainThread | ||
} | ||
exports.isWorkerRuntime = isWorkerRuntime; |
@@ -9,6 +9,4 @@ import type { BlobWorker as BlobWorkerClass } from '../types/master'; | ||
export type Worker = WorkerType; | ||
/** Separate class to spawn workers from source code blobs or strings. */ | ||
export declare const BlobWorker: typeof BlobWorkerClass; | ||
/** Worker implementation. Either web worker or a node.js Worker class. */ | ||
export declare const Worker: typeof import("../types/master").WorkerImplementation; | ||
export { isWorkerRuntime } from './implementation'; |
@@ -11,7 +11,5 @@ "use strict"; | ||
Object.defineProperty(exports, "Thread", { enumerable: true, get: function () { return thread_1.Thread; } }); | ||
/** Separate class to spawn workers from source code blobs or strings. */ | ||
exports.BlobWorker = (0, implementation_1.getWorkerImplementation)().blob; | ||
/** Worker implementation. Either web worker or a node.js Worker class. */ | ||
exports.Worker = (0, implementation_1.getWorkerImplementation)().default; | ||
var implementation_2 = require("./implementation"); | ||
Object.defineProperty(exports, "isWorkerRuntime", { enumerable: true, get: function () { return implementation_2.isWorkerRuntime; } }); |
"use strict"; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* | ||
* This source file contains the code for proxying calls in the master thread to calls in the workers | ||
* by `.postMessage()`-ing. | ||
* | ||
* Keep in mind that this code can make or break the program's performance! Need to optimize more… | ||
*/ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -13,3 +6,4 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createProxyModule = exports.createProxyFunction = void 0; | ||
exports.createProxyFunction = createProxyFunction; | ||
exports.createProxyModule = createProxyModule; | ||
const debug_1 = __importDefault(require("debug")); | ||
@@ -81,3 +75,2 @@ const observable_fns_1 = require("observable-fns"); | ||
if (rawArgs.length === 0) { | ||
// Exit early if possible | ||
return { | ||
@@ -124,3 +117,2 @@ args: [], | ||
} | ||
exports.createProxyFunction = createProxyFunction; | ||
function createProxyModule(worker, methodNames) { | ||
@@ -133,2 +125,1 @@ const proxy = {}; | ||
} | ||
exports.createProxyModule = createProxyModule; |
import { Thread } from './thread'; | ||
/** Pool event type. Specifies the type of each `PoolEvent`. */ | ||
export declare enum PoolEventType { | ||
@@ -14,3 +13,2 @@ initialized = "initialized", | ||
export type TaskRunFunction<ThreadType extends Thread, Return> = (worker: ThreadType) => Promise<Return>; | ||
/** Pool event. Subscribe to those events using `pool.events()`. Useful for debugging. */ | ||
export type PoolEvent<ThreadType extends Thread> = { | ||
@@ -49,19 +47,7 @@ type: PoolEventType.initialized; | ||
} | ||
/** | ||
* Task that has been `pool.queued()`-ed. | ||
*/ | ||
export interface QueuedTask<ThreadType extends Thread, Return> { | ||
/** @private */ | ||
id: number; | ||
/** @private */ | ||
run: TaskRunFunction<ThreadType, Return>; | ||
/** | ||
* Queued tasks can be cancelled until the pool starts running them on a worker thread. | ||
*/ | ||
cancel(): void; | ||
/** | ||
* `QueuedTask` is thenable, so you can `await` it. | ||
* Resolves when the task has successfully been executed. Rejects if the task fails. | ||
*/ | ||
then: Promise<Return>['then']; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PoolEventType = void 0; | ||
/** Pool event type. Specifies the type of each `PoolEvent`. */ | ||
var PoolEventType; | ||
@@ -6,0 +5,0 @@ (function (PoolEventType) { |
@@ -8,48 +8,13 @@ import { Observable } from 'observable-fns'; | ||
} | ||
/** | ||
* Thread pool managing a set of worker threads. | ||
* Use it to queue tasks that are run on those threads with limited | ||
* concurrency. | ||
*/ | ||
export interface Pool<ThreadType extends Thread> { | ||
/** | ||
* Returns a promise that resolves once the task queue is emptied. | ||
* Promise will be rejected if any task fails. | ||
* | ||
* @param allowResolvingImmediately Set to `true` to resolve immediately if task queue is currently empty. | ||
*/ | ||
completed(allowResolvingImmediately?: boolean): Promise<any>; | ||
/** | ||
* Returns a promise that resolves once the task queue is emptied. | ||
* Failing tasks will not cause the promise to be rejected. | ||
* | ||
* @param allowResolvingImmediately Set to `true` to resolve immediately if task queue is currently empty. | ||
*/ | ||
settled(allowResolvingImmediately?: boolean): Promise<Error[]>; | ||
/** | ||
* Returns an observable that yields pool events. | ||
*/ | ||
events(): Observable<PoolEvent<ThreadType>>; | ||
/** | ||
* Queue a task and return a promise that resolves once the task has been dequeued, | ||
* started and finished. | ||
* | ||
* @param task An async function that takes a thread instance and invokes it. | ||
*/ | ||
queue<Return>(task: TaskRunFunction<ThreadType, Return>): QueuedTask<ThreadType, Return>; | ||
/** | ||
* Terminate all pool threads. | ||
* | ||
* @param force Set to `true` to kill the thread even if it cannot be stopped gracefully. | ||
*/ | ||
terminate(force?: boolean): Promise<void>; | ||
} | ||
export interface PoolOptions { | ||
/** Maximum no. of tasks to run on one worker thread at a time. Defaults to one. */ | ||
concurrency?: number; | ||
/** Maximum no. of jobs to be queued for execution before throwing an error. */ | ||
maxQueuedJobs?: number; | ||
/** Gives that pool a name to be used for debug logging, letting you distinguish between log output of different pools. */ | ||
name?: string; | ||
/** No. of worker threads to spawn and to be managed by the pool. */ | ||
size?: number; | ||
@@ -80,9 +45,3 @@ } | ||
} | ||
/** | ||
* Thread pool constructor. Creates a new pool and spawns its worker threads. | ||
*/ | ||
declare function PoolConstructor<ThreadType extends Thread>(spawnWorker: () => Promise<ThreadType>, optionsOrSize?: number | PoolOptions): WorkerPool<ThreadType>; | ||
/** | ||
* Thread pool constructor. Creates a new pool and spawns its worker threads. | ||
*/ | ||
export declare const Pool: typeof PoolConstructor & { | ||
@@ -89,0 +48,0 @@ EventType: typeof PoolEventType; |
@@ -7,10 +7,2 @@ "use strict"; | ||
exports.Thread = exports.PoolEventType = exports.Pool = void 0; | ||
/* eslint-disable unicorn/no-thenable */ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
/* eslint-disable require-await */ | ||
/* eslint-disable @typescript-eslint/member-ordering */ | ||
/* eslint-disable unicorn/no-array-reduce */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable import/export */ | ||
/* eslint-disable @typescript-eslint/no-namespace */ | ||
const debug_1 = __importDefault(require("debug")); | ||
@@ -109,3 +101,2 @@ const observable_fns_1 = require("observable-fns"); | ||
}; | ||
// Defer task execution by one tick to give handlers time to subscribe | ||
await delay(0); | ||
@@ -178,3 +169,3 @@ try { | ||
} | ||
}, // make a pool-wide error reject the completed() result promise | ||
}, | ||
}); | ||
@@ -200,3 +191,3 @@ }); | ||
} | ||
}, // make a pool-wide error reject the completed() result promise | ||
}, | ||
}); | ||
@@ -223,4 +214,2 @@ }); | ||
taskCompletion.catch((error) => { | ||
// Prevent unhandled rejections here as we assume the user will use | ||
// `pool.completed()`, `pool.settled()` or `task.catch()` to handle errors | ||
this.debug(`Task #${taskID} errored:`, error); | ||
@@ -269,8 +258,3 @@ }); | ||
} | ||
/** | ||
* Thread pool constructor. Creates a new pool and spawns its worker threads. | ||
*/ | ||
function PoolConstructor(spawnWorker, optionsOrSize) { | ||
// The function exists only so we don't need to use `new` to create a pool (we still can, though). | ||
// If the Pool is a class or not is an implementation detail that should not concern the user. | ||
return new WorkerPool(spawnWorker, optionsOrSize); | ||
@@ -280,5 +264,2 @@ } | ||
PoolConstructor.EventType = pool_types_1.PoolEventType; | ||
/** | ||
* Thread pool constructor. Creates a new pool and spawns its worker threads. | ||
*/ | ||
exports.Pool = PoolConstructor; | ||
@@ -285,0 +266,0 @@ var pool_types_2 = require("./pool-types"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const index_1 = require("./index"); | ||
@@ -5,0 +4,0 @@ if (typeof global !== 'undefined') { |
@@ -8,11 +8,2 @@ import { FunctionThread, ModuleThread, StripAsync, Worker as WorkerType } from '../types/master'; | ||
export type ExposedToThreadType<Exposed extends WorkerFunction | WorkerModule<any>> = Exposed extends ArbitraryWorkerInterface ? ArbitraryThreadType : Exposed extends WorkerFunction ? FunctionThread<Parameters<Exposed>, StripAsync<ReturnType<Exposed>>> : Exposed extends WorkerModule<any> ? ModuleThread<Exposed> : never; | ||
/** | ||
* Spawn a new thread. Takes a fresh worker instance, wraps it in a thin | ||
* abstraction layer to provide the transparent API and verifies that | ||
* the worker has initialized successfully. | ||
* | ||
* @param worker Instance of `Worker`. Either a web worker, `worker_threads` worker or `tiny-worker` worker. | ||
* @param [options] | ||
* @param [options.timeout] Init message timeout. Default: 10000 or set by environment variable. | ||
*/ | ||
export declare function spawn<Exposed extends WorkerFunction | WorkerModule<any> = ArbitraryWorkerInterface>(worker: WorkerType, options?: { | ||
@@ -19,0 +10,0 @@ timeout?: number; |
@@ -6,5 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.spawn = void 0; | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
exports.spawn = spawn; | ||
const debug_1 = __importDefault(require("debug")); | ||
@@ -84,3 +82,2 @@ const observable_fns_1 = require("observable-fns"); | ||
debugThreadUtils('Terminating worker'); | ||
// Newer versions of worker_threads workers return a promise | ||
await worker.terminate(); | ||
@@ -95,3 +92,2 @@ resolver(); | ||
.map((errorEvent) => errorEvent.error); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return Object.assign(raw, { | ||
@@ -104,11 +100,2 @@ [symbols_1.$errors]: workerErrors, | ||
} | ||
/** | ||
* Spawn a new thread. Takes a fresh worker instance, wraps it in a thin | ||
* abstraction layer to provide the transparent API and verifies that | ||
* the worker has initialized successfully. | ||
* | ||
* @param worker Instance of `Worker`. Either a web worker, `worker_threads` worker or `tiny-worker` worker. | ||
* @param [options] | ||
* @param [options.timeout] Init message timeout. Default: 10000 or set by environment variable. | ||
*/ | ||
async function spawn(worker, options) { | ||
@@ -134,2 +121,1 @@ debugSpawn('Initializing new thread'); | ||
} | ||
exports.spawn = spawn; |
import { Observable } from 'observable-fns'; | ||
import { Thread as ThreadType, WorkerEvent } from '../types/master'; | ||
export type Thread = ThreadType; | ||
/** Thread utility functions. Use them to manage or inspect a `spawn()`-ed thread. */ | ||
export declare const Thread: { | ||
/** Return an observable that can be used to subscribe to all errors happening in the thread. */ | ||
errors<ThreadT extends ThreadType>(thread: ThreadT): Observable<Error>; | ||
/** Return an observable that can be used to subscribe to internal events happening in the thread. Useful for debugging. */ | ||
events<ThreadT_1 extends ThreadType>(thread: ThreadT_1): Observable<WorkerEvent>; | ||
/** Terminate a thread. Remember to terminate every thread when you are done using it. */ | ||
terminate<ThreadT_2 extends ThreadType>(thread: ThreadT_2): Promise<void>; | ||
events<ThreadT extends ThreadType>(thread: ThreadT): Observable<WorkerEvent>; | ||
terminate<ThreadT extends ThreadType>(thread: ThreadT): Promise<void>; | ||
}; |
@@ -8,13 +8,9 @@ "use strict"; | ||
} | ||
/** Thread utility functions. Use them to manage or inspect a `spawn()`-ed thread. */ | ||
exports.Thread = { | ||
/** Return an observable that can be used to subscribe to all errors happening in the thread. */ | ||
errors(thread) { | ||
return thread[symbols_1.$errors] || fail('Error observable not found. Make sure to pass a thread instance as returned by the spawn() promise.'); | ||
}, | ||
/** Return an observable that can be used to subscribe to internal events happening in the thread. Useful for debugging. */ | ||
events(thread) { | ||
return thread[symbols_1.$events] || fail('Events observable not found. Make sure to pass a thread instance as returned by the spawn() promise.'); | ||
}, | ||
/** Terminate a thread. Remember to terminate every thread when you are done using it. */ | ||
terminate(thread) { | ||
@@ -21,0 +17,0 @@ return thread[symbols_1.$terminate](); |
@@ -7,15 +7,2 @@ import { Observable, ObservableLike, SubscriptionObserver } from 'observable-fns'; | ||
type UnsubscribeFn = () => void; | ||
/** | ||
* Creates a hybrid, combining the APIs of an Observable and a Promise. | ||
* | ||
* It is used to proxy async process states when we are initially not sure | ||
* if that async process will yield values once (-> Promise) or multiple | ||
* times (-> Observable). | ||
* | ||
* Note that the observable promise inherits some of the observable's characteristics: | ||
* The `init` function will be called *once for every time anyone subscribes to it*. | ||
* | ||
* If this is undesired, derive a hot observable from it using `makeHot()` and | ||
* subscribe to that. | ||
*/ | ||
export declare class ObservablePromise<T> extends Observable<T> implements Promise<T> { | ||
@@ -22,0 +9,0 @@ readonly [Symbol.toStringTag] = "[object ObservablePromise]"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ObservablePromise = void 0; | ||
/* eslint-disable unicorn/no-thenable */ | ||
/* eslint-disable @typescript-eslint/member-ordering */ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-this-alias */ | ||
/* eslint-disable unicorn/no-this-assignment */ | ||
const observable_fns_1 = require("observable-fns"); | ||
@@ -20,15 +14,2 @@ const doNothing = () => { }; | ||
} | ||
/** | ||
* Creates a hybrid, combining the APIs of an Observable and a Promise. | ||
* | ||
* It is used to proxy async process states when we are initially not sure | ||
* if that async process will yield values once (-> Promise) or multiple | ||
* times (-> Observable). | ||
* | ||
* Note that the observable promise inherits some of the observable's characteristics: | ||
* The `init` function will be called *once for every time anyone subscribes to it*. | ||
* | ||
* If this is undesired, derive a hot observable from it using `makeHot()` and | ||
* subscribe to that. | ||
*/ | ||
class ObservablePromise extends observable_fns_1.Observable { | ||
@@ -45,3 +26,2 @@ [Symbol.toStringTag] = '[object ObservablePromise]'; | ||
super((originalObserver) => { | ||
// tslint:disable-next-line no-this-assignment | ||
const self = this; | ||
@@ -82,4 +62,2 @@ const observer = { | ||
for (const onRejected of this.rejectionCallbacks) { | ||
// Promisifying the call to turn errors into unhandled promise rejections | ||
// instead of them failing sync and cancelling the iteration | ||
runDeferred(() => onRejected(error)); | ||
@@ -91,4 +69,2 @@ } | ||
for (const onFulfilled of this.fulfillmentCallbacks) { | ||
// Promisifying the call to turn errors into unhandled promise rejections | ||
// instead of them failing sync and cancelling the iteration | ||
runDeferred(() => onFulfilled(this.firstValue)); | ||
@@ -95,0 +71,0 @@ } |
import { Observable, ObservableLike } from 'observable-fns'; | ||
declare const $observers: unique symbol; | ||
/** | ||
* Observable subject. Implements the Observable interface, but also exposes | ||
* the `next()`, `error()`, `complete()` methods to initiate observable | ||
* updates "from the outside". | ||
* | ||
* Use `Observable.from(subject)` to derive an observable that proxies all | ||
* values, errors and the completion raised on this subject, but does not | ||
* expose the `next()`, `error()`, `complete()` methods. | ||
*/ | ||
export declare class Subject<T> extends Observable<T> implements ObservableLike<T> { | ||
@@ -13,0 +4,0 @@ private [$observers]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Observable = exports.Subject = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const observable_fns_1 = require("observable-fns"); | ||
const $observers = Symbol('observers'); | ||
/** | ||
* Observable subject. Implements the Observable interface, but also exposes | ||
* the `next()`, `error()`, `complete()` methods to initiate observable | ||
* updates "from the outside". | ||
* | ||
* Use `Observable.from(subject)` to derive an observable that proxies all | ||
* values, errors and the completion raised on this subject, but does not | ||
* expose the `next()`, `error()`, `complete()` methods. | ||
*/ | ||
class Subject extends observable_fns_1.Observable { | ||
@@ -17,0 +7,0 @@ [$observers]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.allSettled = void 0; | ||
// Based on <https://github.com/es-shims/Promise.allSettled/blob/master/implementation.js> | ||
exports.allSettled = allSettled; | ||
function allSettled(values) { | ||
@@ -22,2 +21,1 @@ return Promise.all(values.map((item) => { | ||
} | ||
exports.allSettled = allSettled; |
@@ -1,5 +0,1 @@ | ||
/** | ||
* Creates a new promise and exposes its resolver function. | ||
* Use with care! | ||
*/ | ||
export declare function createPromiseWithResolver<T>(): [Promise<T>, (result: T) => void]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createPromiseWithResolver = void 0; | ||
// eslint-disable-next-line unicorn/no-useless-undefined | ||
exports.createPromiseWithResolver = createPromiseWithResolver; | ||
const doNothing = () => undefined; | ||
/** | ||
* Creates a new promise and exposes its resolver function. | ||
* Use with care! | ||
*/ | ||
function createPromiseWithResolver() { | ||
@@ -29,2 +24,1 @@ let alreadyResolved = false; | ||
} | ||
exports.createPromiseWithResolver = createPromiseWithResolver; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DefaultSerializer = exports.extendSerializer = void 0; | ||
exports.DefaultSerializer = void 0; | ||
exports.extendSerializer = extendSerializer; | ||
function extendSerializer(extend, implementation) { | ||
@@ -16,3 +17,2 @@ const fallbackDeserializer = extend.deserialize.bind(extend); | ||
} | ||
exports.extendSerializer = extendSerializer; | ||
const DefaultErrorSerializer = { | ||
@@ -19,0 +19,0 @@ deserialize(message) { |
@@ -8,36 +8,3 @@ import { $transferable } from './symbols'; | ||
export declare function isTransferDescriptor(thing: any): thing is TransferDescriptor; | ||
/** | ||
* Mark a transferable object as such, so it will no be serialized and | ||
* deserialized on messaging with the main thread, but to transfer | ||
* ownership of it to the receiving thread. | ||
* | ||
* Only works with array buffers, message ports and few more special | ||
* types of objects, but it's much faster than serializing and | ||
* deserializing them. | ||
* | ||
* Note: | ||
* The transferable object cannot be accessed by this thread again | ||
* unless the receiving thread transfers it back again! | ||
* | ||
* @param transferable Array buffer, message port or similar. | ||
* @see <https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast> | ||
*/ | ||
export declare function Transfer(transferable: Transferable): TransferDescriptor; | ||
/** | ||
* Mark transferable objects within an arbitrary object or array as | ||
* being a transferable object. They will then not be serialized | ||
* and deserialized on messaging with the main thread, but ownership | ||
* of them will be tranferred to the receiving thread. | ||
* | ||
* Only array buffers, message ports and few more special types of | ||
* objects can be transferred, but it's much faster than serializing and | ||
* deserializing them. | ||
* | ||
* Note: | ||
* The transferable object cannot be accessed by this thread again | ||
* unless the receiving thread transfers it back again! | ||
* | ||
* @param transferable Array buffer, message port or similar. | ||
* @see <https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast> | ||
*/ | ||
export declare function Transfer<T>(payload: T, transferables: Transferable[]): TransferDescriptor; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Transfer = exports.isTransferDescriptor = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
exports.isTransferDescriptor = isTransferDescriptor; | ||
exports.Transfer = Transfer; | ||
const symbols_1 = require("./symbols"); | ||
@@ -9,3 +9,2 @@ function isTransferable(thing) { | ||
return false; | ||
// Don't check too thoroughly, since the list of transferable things in JS might grow over time | ||
return true; | ||
@@ -16,3 +15,2 @@ } | ||
} | ||
exports.isTransferDescriptor = isTransferDescriptor; | ||
function Transfer(payload, transferables) { | ||
@@ -30,2 +28,1 @@ if (!transferables) { | ||
} | ||
exports.Transfer = Transfer; |
@@ -1,2 +0,1 @@ | ||
/// <reference lib="dom" /> | ||
import { Observable } from 'observable-fns'; | ||
@@ -40,29 +39,18 @@ import { ObservablePromise } from '../observable-promise'; | ||
} | ||
/** Worker thread. Either a `FunctionThread` or a `ModuleThread`. */ | ||
export type Thread = AnyFunctionThread | AnyModuleThread; | ||
export type TransferList = Transferable[]; | ||
/** Worker instance. Either a web worker or a node.js Worker provided by `worker_threads` or `tiny-worker`. */ | ||
export interface Worker extends EventTarget { | ||
postMessage(value: any, transferList?: TransferList): void; | ||
/** In nodejs 10+ return type is Promise while with tiny-worker and in browser return type is void */ | ||
terminate(callback?: (error?: Error, exitCode?: number) => void): void | Promise<number>; | ||
} | ||
export interface ThreadsWorkerOptions extends WorkerOptions { | ||
/** Whether to apply CORS protection workaround. Defaults to true. */ | ||
CORSWorkaround?: boolean; | ||
/** Prefix for the path passed to the Worker constructor. Web worker only. */ | ||
_baseURL?: string; | ||
/** Resource limits passed on to Node worker_threads */ | ||
resourceLimits?: { | ||
/** The size of a pre-allocated memory range used for generated code. */ | ||
codeRangeSizeMb?: number; | ||
/** The maximum size of the main heap in MB. */ | ||
maxOldGenerationSizeMb?: number; | ||
/** The maximum size of a heap space for recently created objects. */ | ||
maxYoungGenerationSizeMb?: number; | ||
}; | ||
/** Data passed on to node.js worker_threads. */ | ||
workerData?: any; | ||
} | ||
/** Worker implementation. Either web worker or a node.js Worker class. */ | ||
export declare class WorkerImplementation extends EventTarget implements Worker { | ||
@@ -73,3 +61,2 @@ constructor(path: string, options?: ThreadsWorkerOptions); | ||
} | ||
/** Class to spawn workers from a blob or source string. */ | ||
export declare class BlobWorker extends WorkerImplementation { | ||
@@ -83,3 +70,2 @@ constructor(blob: Blob, options?: ThreadsWorkerOptions); | ||
} | ||
/** Event as emitted by worker thread. Subscribe to using `Thread.events(thread)`. */ | ||
export declare enum WorkerEventType { | ||
@@ -86,0 +72,0 @@ internalError = "internalError", |
"use strict"; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/// <reference lib="dom" /> | ||
// tslint:disable max-classes-per-file | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WorkerEventType = void 0; | ||
const symbols_1 = require("../symbols"); | ||
/** Event as emitted by worker thread. Subscribe to using `Thread.events(thread)`. */ | ||
var WorkerEventType; | ||
@@ -10,0 +6,0 @@ (function (WorkerEventType) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WorkerMessageType = exports.MasterMessageType = void 0; | ||
///////////////////////////// | ||
// Messages sent by master: | ||
var MasterMessageType; | ||
@@ -11,4 +9,2 @@ (function (MasterMessageType) { | ||
})(MasterMessageType || (exports.MasterMessageType = MasterMessageType = {})); | ||
//////////////////////////// | ||
// Messages sent by worker: | ||
var WorkerMessageType; | ||
@@ -15,0 +11,0 @@ (function (WorkerMessageType) { |
"use strict"; | ||
/* eslint-disable import/no-default-export */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
// Webpack hack | ||
// tslint:disable no-eval | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = getImplementation; | ||
let implementation; | ||
@@ -17,2 +14,1 @@ function selectImplementation() { | ||
} | ||
exports.default = getImplementation; |
@@ -17,3 +17,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const index_1 = require("./index"); | ||
@@ -20,0 +19,0 @@ __exportStar(require("./index"), exports); |
@@ -1,7 +0,6 @@ | ||
/// <reference lib="dom" /> | ||
declare const _default: { | ||
isWorkerRuntime: () => boolean; | ||
postMessageToMaster: (message: any, transferList?: Transferable[] | undefined) => void; | ||
postMessageToMaster: (message: any, transferList?: Transferable[]) => void; | ||
subscribeToMasterMessages: (onMessage: (data: any) => void) => () => void; | ||
}; | ||
export default _default; |
"use strict"; | ||
/* eslint-disable import/no-default-export */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/// <reference lib="dom" /> | ||
// tslint:disable no-shadowed-variable | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -7,0 +3,0 @@ const isWorkerRuntime = function isWorkerRuntime() { |
"use strict"; | ||
/* eslint-disable import/no-default-export */ | ||
// tslint:disable no-var-requires | ||
/* | ||
* This file is only a stub to make './implementation' resolve to the right module. | ||
*/ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -8,0 +3,0 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; |
@@ -1,7 +0,6 @@ | ||
/// <reference lib="dom" /> | ||
declare const _default: { | ||
isWorkerRuntime: () => boolean; | ||
postMessageToMaster: (message: any, transferList?: Transferable[] | undefined) => void; | ||
postMessageToMaster: (message: any, transferList?: Transferable[]) => void; | ||
subscribeToMasterMessages: (onMessage: (data: any) => void) => () => void; | ||
}; | ||
export default _default; |
"use strict"; | ||
/* eslint-disable import/no-default-export */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/// <reference lib="dom" /> | ||
// tslint:disable no-shadowed-variable | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -21,3 +17,2 @@ try { | ||
const postMessageToMaster = function postMessageToMaster(data) { | ||
// TODO: Warn that Transferables are not supported on first attempt to use feature | ||
self.postMessage(data); | ||
@@ -29,4 +24,2 @@ }; | ||
if (!muxingHandlerSetUp) { | ||
// We have one multiplexing message handler as tiny-worker's | ||
// addEventListener() only allows you to set a single message handler | ||
self.addEventListener('message', ((event) => { | ||
@@ -33,0 +26,0 @@ for (const handler of messageHandlers) |
declare function testImplementation(): void; | ||
declare const _default: { | ||
isWorkerRuntime: () => boolean; | ||
postMessageToMaster: (message: any, transferList?: Transferable[] | undefined) => void; | ||
postMessageToMaster: (message: any, transferList?: Transferable[]) => void; | ||
subscribeToMasterMessages: (onMessage: (data: any) => void) => () => void; | ||
@@ -6,0 +6,0 @@ testImplementation: typeof testImplementation; |
@@ -34,3 +34,2 @@ "use strict"; | ||
function testImplementation() { | ||
// Will throw if `worker_threads` are not available | ||
(0, worker_threads_1.default)(); | ||
@@ -37,0 +36,0 @@ } |
import { WorkerFunction, WorkerModule } from '../types/worker'; | ||
export { registerSerializer } from '../common'; | ||
export { Transfer } from '../transferable'; | ||
/** Returns `true` if this code is currently running in a worker. */ | ||
export declare const isWorkerRuntime: () => boolean; | ||
/** | ||
* Expose a function or a module (an object whose values are functions) | ||
* to the main thread. Must be called exactly once in every worker thread | ||
* to signal its API to the main thread. | ||
* | ||
* @param exposed Function or object whose values are functions | ||
*/ | ||
export declare function expose(exposed: WorkerFunction | WorkerModule<any>): void; |
@@ -6,5 +6,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.expose = exports.isWorkerRuntime = exports.Transfer = exports.registerSerializer = void 0; | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
exports.isWorkerRuntime = exports.Transfer = exports.registerSerializer = void 0; | ||
exports.expose = expose; | ||
const is_observable_2_1_0_1 = __importDefault(require("is-observable-2-1-0")); | ||
@@ -19,3 +18,2 @@ const common_1 = require("../common"); | ||
Object.defineProperty(exports, "Transfer", { enumerable: true, get: function () { return transferable_2.Transfer; } }); | ||
/** Returns `true` if this code is currently running in a worker. */ | ||
exports.isWorkerRuntime = implementation_1.default.isWorkerRuntime; | ||
@@ -26,6 +24,2 @@ let exposeCalled = false; | ||
const isMasterJobRunMessage = (thing) => thing && thing.type === messages_1.MasterMessageType.run; | ||
/** | ||
* There are issues with `is-observable` not recognizing zen-observable's instances. | ||
* We are using `observable-fns`, but it's based on zen-observable, too. | ||
*/ | ||
const isObservable = (thing) => (0, is_observable_2_1_0_1.default)(thing) || isZenObservable(thing); | ||
@@ -93,3 +87,2 @@ function isZenObservable(thing) { | ||
catch (subError) { | ||
// tslint:disable-next-line no-console | ||
console.error('Not reporting uncaught error back to master thread as it ' + 'occured while reporting an uncaught error already.' + '\nLatest error:', subError, '\nOriginal error:', error); | ||
@@ -128,9 +121,2 @@ } | ||
} | ||
/** | ||
* Expose a function or a module (an object whose values are functions) | ||
* to the main thread. Must be called exactly once in every worker thread | ||
* to signal its API to the main thread. | ||
* | ||
* @param exposed Function or object whose values are functions | ||
*/ | ||
function expose(exposed) { | ||
@@ -175,6 +161,4 @@ if (!implementation_1.default.isWorkerRuntime()) { | ||
} | ||
exports.expose = expose; | ||
if (typeof self !== 'undefined' && typeof self.addEventListener === 'function' && implementation_1.default.isWorkerRuntime()) { | ||
self.addEventListener('error', (event) => { | ||
// Post with some delay, so the master had some time to subscribe to messages | ||
setTimeout(() => postUncaughtErrorMessage(event.error || event), 250); | ||
@@ -185,3 +169,2 @@ }); | ||
if (error && typeof error.message === 'string') { | ||
// Post with some delay, so the master had some time to subscribe to messages | ||
setTimeout(() => postUncaughtErrorMessage(error), 250); | ||
@@ -193,3 +176,2 @@ } | ||
process.on('uncaughtException', (error) => { | ||
// Post with some delay, so the master had some time to subscribe to messages | ||
setTimeout(() => postUncaughtErrorMessage(error), 250); | ||
@@ -199,3 +181,2 @@ }); | ||
if (error && typeof error.message === 'string') { | ||
// Post with some delay, so the master had some time to subscribe to messages | ||
setTimeout(() => postUncaughtErrorMessage(error), 250); | ||
@@ -202,0 +183,0 @@ } |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
export * from './dist/observable' |
@@ -1,3 +0,1 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
/* eslint-disable no-undef */ | ||
module.exports = require('./dist/observable') |
{ | ||
"name": "@xylabs/threads", | ||
"version": "3.5.1", | ||
"version": "3.5.2", | ||
"description": "Web workers & worker threads as simple as a function call", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"module": "dist-esm/index.js", | ||
"module": "dist/esm/index.js", | ||
"scripts": { | ||
@@ -16,3 +16,3 @@ "package-compile": "yarn build", | ||
"postbuild": "npm run bundle", | ||
"bundle": "rollup -c -f umd --file=bundle/worker.js --name=threads --silent -- dist-esm/worker/bundle-entry.js", | ||
"bundle": "rollup -c -f umd --file=bundle/worker.js --name=threads --silent -- dist/esm/worker/bundle-entry.js", | ||
"test": "npm run test:library && npm run test:tooling && npm run test:puppeteer:basic && npm run test:puppeteer:webpack", | ||
@@ -70,5 +70,5 @@ "test:library": "cross-env TS_NODE_FILES=true ava ./test/**/*.test.ts", | ||
"dependencies": { | ||
"@babel/types": "^7.24.6", | ||
"@babel/types": "^7.24.7", | ||
"callsites-3-1-0": "npm:callsites@3.1.0", | ||
"debug": "^4.3.4", | ||
"debug": "^4.3.5", | ||
"is-observable-2-1-0": "npm:is-observable@2.1.0", | ||
@@ -78,3 +78,3 @@ "observable-fns": "^0.6.1" | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^25.0.8", | ||
"@rollup/plugin-commonjs": "^26.0.1", | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
@@ -84,3 +84,3 @@ "@types/chai": "^4.3.16", | ||
"@types/execa": "^2.0.0", | ||
"@types/node": "^20.12.12", | ||
"@types/node": "^20.14.8", | ||
"@types/webpack": "^5.28.5", | ||
@@ -90,4 +90,4 @@ "ava": "^6.1.3", | ||
"cross-env": "^7.0.3", | ||
"execa": "^9.1.0", | ||
"mocha": "^10.4.0", | ||
"execa": "^9.3.0", | ||
"mocha": "^10.5.1", | ||
"puppet-run": "^0.11.4", | ||
@@ -102,5 +102,5 @@ "puppet-run-plugin-mocha": "^0.1.1", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.4.5", | ||
"typescript": "^5.5.2", | ||
"wavy": "^1.0.4", | ||
"webpack": "^5.91.0", | ||
"webpack": "^5.92.1", | ||
"worker-plugin": "^5.0.1" | ||
@@ -125,7 +125,7 @@ }, | ||
"browser": { | ||
"./dist-esm/master/implementation.js": "./dist-esm/master/implementation.browser.js", | ||
"./dist-esm/master/implementation.node.js": false, | ||
"./dist-esm/worker/implementation.js": "./dist-esm/worker/implementation.browser.js", | ||
"./dist-esm/worker/implementation.tiny-worker.js": false, | ||
"./dist-esm/worker/implementation.worker_threads.js": false, | ||
"./dist/esm/master/implementation.js": "./dist/esm/master/implementation.browser.js", | ||
"./dist/esm/master/implementation.node.js": false, | ||
"./dist/esm/worker/implementation.js": "./dist/esm/worker/implementation.browser.js", | ||
"./dist/esm/worker/implementation.tiny-worker.js": false, | ||
"./dist/esm/worker/implementation.worker_threads.js": false, | ||
"./dist/master/implementation.js": "./dist/master/implementation.browser.js", | ||
@@ -147,3 +147,2 @@ "./dist/master/implementation.node.js": false, | ||
"dist/**", | ||
"dist-esm/**", | ||
"*.js", | ||
@@ -150,0 +149,0 @@ "*.mjs", |
@@ -1,3 +0,1 @@ | ||
/* eslint-disable import/export */ | ||
/* eslint-disable import/no-internal-modules */ | ||
export * from './dist/master/register' |
@@ -1,3 +0,1 @@ | ||
/* eslint-disable no-undef */ | ||
/* eslint-disable import/no-internal-modules */ | ||
require('./dist/master/register') |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable no-undef */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
@@ -3,0 +2,0 @@ const commonjs = require('@rollup/plugin-commonjs') |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
export { registerSerializer } from './common' | ||
@@ -3,0 +2,0 @@ export * from './master/index' |
/* eslint-disable unicorn/no-thenable */ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
/* eslint-disable require-await */ | ||
@@ -9,2 +9,3 @@ /* eslint-disable @typescript-eslint/member-ordering */ | ||
/* eslint-disable @typescript-eslint/no-namespace */ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
import DebugLogger from 'debug' | ||
@@ -11,0 +12,0 @@ import { multicast, Observable, Subject } from 'observable-fns' |
@@ -0,3 +1,3 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import DebugLogger from 'debug' | ||
@@ -127,3 +127,2 @@ import { Observable } from 'observable-fns' | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return Object.assign(raw as any, { | ||
@@ -130,0 +129,0 @@ [$errors]: workerErrors, |
/* eslint-disable unicorn/no-thenable */ | ||
/* eslint-disable @typescript-eslint/member-ordering */ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
@@ -5,0 +6,0 @@ /* eslint-disable @typescript-eslint/no-this-alias */ |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-default-export */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
@@ -23,2 +22,3 @@ // Webpack hack | ||
// eslint-disable-next-line import/no-default-export | ||
export default function getImplementation(): WorkerThreadsModule { | ||
@@ -25,0 +25,0 @@ if (!implementation) { |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-default-export */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
@@ -36,2 +35,3 @@ /// <reference lib="dom" /> | ||
// eslint-disable-next-line import/no-default-export | ||
export default { | ||
@@ -38,0 +38,0 @@ isWorkerRuntime, |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-default-export */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
@@ -51,2 +50,3 @@ /// <reference lib="dom" /> | ||
// eslint-disable-next-line import/no-default-export | ||
export default { | ||
@@ -53,0 +53,0 @@ isWorkerRuntime, |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-default-export */ | ||
// tslint:disable no-var-requires | ||
@@ -23,2 +22,3 @@ /* | ||
// eslint-disable-next-line import/no-default-export | ||
export default runningInNode ? selectNodeImplementation() : WebWorkerImplementation |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-default-export */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
@@ -45,2 +44,3 @@ // tslint:disable no-shadowed-variable | ||
// eslint-disable-next-line import/no-default-export | ||
export default { | ||
@@ -47,0 +47,0 @@ isWorkerRuntime, |
@@ -0,3 +1,3 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import isSomeObservable from 'is-observable-2-1-0' | ||
@@ -4,0 +4,0 @@ import { Observable, Subscription } from 'observable-fns' |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable no-undef */ | ||
/* eslint-disable no-restricted-imports */ | ||
@@ -3,0 +2,0 @@ import { spawn, Thread, Worker } from '../..' |
@@ -1,5 +0,5 @@ | ||
/* eslint-disable import/no-default-export */ | ||
import commonjs from '@rollup/plugin-commonjs' | ||
import { nodeResolve } from '@rollup/plugin-node-resolve' | ||
// eslint-disable-next-line import/no-default-export | ||
export default { | ||
@@ -6,0 +6,0 @@ plugins: [ |
/* eslint-disable require-await */ | ||
/* eslint-disable import/no-internal-modules */ | ||
import { expose } from '../../dist-esm/worker' | ||
import { expose } from '../../dist/esm/worker' | ||
expose(async function add(a, b) { | ||
return a + b | ||
}) |
@@ -0,3 +1,3 @@ | ||
/* eslint-disable no-restricted-imports */ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
/* eslint-disable no-restricted-imports */ | ||
import { spawn, Thread, Worker } from '../..' | ||
@@ -4,0 +4,0 @@ |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
import { expose, isWorkerRuntime } from '../../src/worker' | ||
@@ -3,0 +2,0 @@ |
@@ -1,5 +0,4 @@ | ||
/* eslint-disable import/no-default-export */ | ||
/* eslint-disable import/no-unresolved */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable import/no-internal-modules */ | ||
/* eslint-disable import/no-unresolved */ | ||
/// <reference types="./raw-loader" /> | ||
@@ -29,2 +28,3 @@ | ||
// eslint-disable-next-line import/no-default-export | ||
export default test |
@@ -1,4 +0,3 @@ | ||
/* eslint-disable import/no-default-export */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable import/no-internal-modules */ | ||
import { isWorkerRuntime, Pool, spawn, Worker } from '../../src/index' | ||
@@ -60,2 +59,3 @@ | ||
// eslint-disable-next-line import/no-default-export | ||
export default testAll |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
import { expose } from '../../src/worker' | ||
@@ -3,0 +2,0 @@ |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable no-undef */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
@@ -3,0 +2,0 @@ const path = require('node:path') |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable no-undef */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
@@ -3,0 +2,0 @@ const path = require('node:path') |
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable import/no-internal-modules */ | ||
import { JsonSerializable, SerializerImplementation } from '../../src/index' | ||
@@ -4,0 +4,0 @@ |
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable import/no-internal-modules */ | ||
import test from 'ava' | ||
@@ -4,0 +3,0 @@ import { Observable } from 'observable-fns' |
/* eslint-disable require-await */ | ||
/* eslint-disable import/no-internal-modules */ | ||
import test from 'ava' | ||
@@ -4,0 +4,0 @@ |
@@ -0,5 +1,6 @@ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
/* eslint-disable require-await */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
/* eslint-disable import/no-internal-modules */ | ||
// eslint-disable import/no-internal-modules | ||
import test from 'ava' | ||
@@ -6,0 +7,0 @@ |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
import test from 'ava' | ||
@@ -3,0 +2,0 @@ |
/* eslint-disable no-restricted-imports */ | ||
/* eslint-disable import/no-internal-modules */ | ||
/* | ||
@@ -4,0 +3,0 @@ * This code here will be run in a headless Chromium browser using `puppet-run`. |
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable import/no-internal-modules */ | ||
import test from 'ava' | ||
@@ -50,3 +49,3 @@ import { Observable } from 'observable-fns' | ||
const fail = await spawn<() => Promise<never>>(new Worker('./workers/faulty-function')) | ||
await t.throwsAsync(fail(), null, 'I am supposed to fail.') | ||
await t.throwsAsync(fail(), undefined, 'I am supposed to fail.') | ||
await Thread.terminate(fail) | ||
@@ -69,5 +68,5 @@ }) | ||
test('catches top-level thread errors', async (t) => { | ||
await t.throwsAsync(spawn(new Worker('./workers/top-level-throw')), null, 'Top-level worker error') | ||
await t.throwsAsync(spawn(new Worker('./workers/top-level-throw')), undefined, 'Top-level worker error') | ||
}) | ||
test.todo('can subscribe to thread events') |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
import test from 'ava' | ||
@@ -3,0 +2,0 @@ |
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable import/no-internal-modules */ | ||
import test from 'ava' | ||
@@ -5,0 +5,0 @@ |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
import { expose, Transfer } from '../../src/worker' | ||
@@ -3,0 +2,0 @@ |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
import { Observable } from 'observable-fns' | ||
@@ -3,0 +2,0 @@ |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
import { expose } from '../../src/worker' | ||
@@ -3,0 +2,0 @@ |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
import { expose } from '../../src/worker' | ||
@@ -3,0 +2,0 @@ |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
import { expose } from '../../src/worker' | ||
@@ -3,0 +2,0 @@ |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
import { expose } from '../../src/worker' | ||
@@ -3,0 +2,0 @@ |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
import { Observable, Subject } from '../../src/observable' | ||
@@ -3,0 +2,0 @@ import { expose } from '../../src/worker' |
/* eslint-disable require-await */ | ||
/* eslint-disable import/no-internal-modules */ | ||
import { expose, registerSerializer } from '../../src/worker' | ||
@@ -4,0 +4,0 @@ import { Foo, fooSerializer } from '../lib/serialization' |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
export * from './dist/worker/index' |
@@ -1,3 +0,1 @@ | ||
/* eslint-disable import/no-internal-modules */ | ||
/* eslint-disable no-undef */ | ||
module.exports = require('./dist/worker/index') |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
261949
6449
Updated@babel/types@^7.24.7
Updateddebug@^4.3.5