Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

threads

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

threads - npm Package Compare versions

Comparing version 1.0.0-beta-esm to 1.0.0-beta-esm.1

dist-esm/common.js

8

dist/master/implementation.browser.d.ts
import { WorkerImplementation } from "../types/master";
declare function selectWorkerImplementation(): typeof WorkerImplementation;
declare const _default: {
defaultPoolSize: number;
selectWorkerImplementation: typeof selectWorkerImplementation;
};
export default _default;
export declare const defaultPoolSize: number;
export declare function selectWorkerImplementation(): typeof WorkerImplementation;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const defaultPoolSize = navigator.hardwareConcurrency || 4;
exports.defaultPoolSize = typeof navigator !== "undefined" && navigator.hardwareConcurrency
? navigator.hardwareConcurrency
: 4;
function selectWorkerImplementation() {
return Worker;
}
exports.default = {
defaultPoolSize,
selectWorkerImplementation
};
exports.selectWorkerImplementation = selectWorkerImplementation;

@@ -1,7 +0,3 @@

import { WorkerImplementation } from "../types/master";
interface ImplementationExports {
defaultPoolSize: number;
selectWorkerImplementation(): typeof WorkerImplementation;
}
declare const _default: ImplementationExports;
export default _default;
import * as BrowserImplementation from "./implementation.browser";
export declare const defaultPoolSize: number;
export declare const selectWorkerImplementation: typeof BrowserImplementation.selectWorkerImplementation;
"use strict";
// tslint:disable no-var-requires
/*
* This file is only a stub to make './implementation' resolve to the right module.
*/
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = typeof process !== 'undefined' && process.arch !== 'browser' && 'pid' in process
? require('./implementation.node').default
: require('./implementation.browser').default;
// 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"));
const NodeImplementation = __importStar(require("./implementation.node"));
const runningInNode = typeof process !== 'undefined' && process.arch !== 'browser' && 'pid' in process;
const implementation = runningInNode ? NodeImplementation : BrowserImplementation;
exports.defaultPoolSize = implementation.defaultPoolSize;
exports.selectWorkerImplementation = implementation.selectWorkerImplementation;
import { WorkerImplementation } from "../types/master";
declare function selectWorkerImplementation(): typeof WorkerImplementation;
declare const _default: {
defaultPoolSize: number;
selectWorkerImplementation: typeof selectWorkerImplementation;
};
export default _default;
export declare const defaultPoolSize: number;
export declare function selectWorkerImplementation(): typeof WorkerImplementation;

@@ -18,3 +18,3 @@ "use strict";

const path = __importStar(require("path"));
const defaultPoolSize = os_1.cpus().length;
exports.defaultPoolSize = os_1.cpus().length;
function rebaseScriptPath(scriptPath, ignoreRegex) {

@@ -107,5 +107,2 @@ const parentCallSite = callsites_1.default().find((callsite) => {

}
exports.default = {
defaultPoolSize,
selectWorkerImplementation
};
exports.selectWorkerImplementation = selectWorkerImplementation;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const implementation_1 = __importDefault(require("./implementation"));
const implementation_1 = require("./implementation");
var pool_1 = require("./pool");

@@ -13,2 +10,2 @@ exports.Pool = pool_1.Pool;

exports.Thread = thread_1.Thread;
exports.Worker = implementation_1.default.selectWorkerImplementation();
exports.Worker = implementation_1.selectWorkerImplementation();

@@ -17,3 +17,3 @@ "use strict";

const observable_promise_1 = require("../observable-promise");
const implementation_1 = __importDefault(require("./implementation"));
const implementation_1 = require("./implementation");
const thread_1 = require("./thread");

@@ -94,3 +94,3 @@ exports.Thread = thread_1.Thread;

const debug = debug_1.default(`threads:pool:${slugify(options.name || String(nextPoolID++))}`);
const { concurrency = 1, size = implementation_1.default.defaultPoolSize } = options;
const { concurrency = 1, size = implementation_1.defaultPoolSize } = options;
let isClosing = false;

@@ -97,0 +97,0 @@ let nextTaskID = 1;

@@ -7,6 +7,6 @@ import Observable from "zen-observable";

};
declare type ArbitraryFunctionOrModuleThread = FunctionThread<any, any> & ModuleThread<any>;
declare type ExposedToThreadType<Exposed extends WorkerFunction | WorkerModule<any>> = Exposed extends ArbitraryWorkerInterface ? ArbitraryFunctionOrModuleThread : Exposed extends WorkerFunction ? FunctionThread<Parameters<Exposed>, StripAsync<ReturnType<Exposed>>> : Exposed extends WorkerModule<any> ? ModuleThread<Exposed> : never;
declare type ArbitraryThreadType = FunctionThread<any, any> & ModuleThread<any>;
declare 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;
declare type StripAsync<Type> = Type extends Promise<infer PromiseBaseType> ? PromiseBaseType : Type extends Observable<infer ObservableBaseType> ? ObservableBaseType : Type;
export declare function spawn<Exposed extends WorkerFunction | WorkerModule<any> = ArbitraryWorkerInterface>(worker: WorkerType): Promise<ExposedToThreadType<Exposed>>;
export {};

@@ -1,3 +0,8 @@

export declare const MessagePort: any;
export declare const isMainThread: any;
export declare const parentPort: any;
declare type MessagePort = any;
interface WorkerThreadsModule {
MessagePort: typeof MessagePort;
isMainThread: boolean;
parentPort: MessagePort;
}
export default function getImplementation(): WorkerThreadsModule;
export {};

@@ -5,7 +5,14 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const workerThreads = typeof __non_webpack_require__ === "function"
? __non_webpack_require__("worker_threads")
: eval("require")("worker_threads");
exports.MessagePort = workerThreads.MessagePort;
exports.isMainThread = workerThreads.isMainThread;
exports.parentPort = workerThreads.parentPort;
let implementation;
function selectImplementation() {
return typeof __non_webpack_require__ === "function"
? __non_webpack_require__("worker_threads")
: eval("require")("worker_threads");
}
function getImplementation() {
if (!implementation) {
implementation = selectImplementation();
}
return implementation;
}
exports.default = getImplementation;

@@ -6,13 +6,28 @@ "use strict";

*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const implementation_browser_1 = __importDefault(require("./implementation.browser"));
const implementation_tiny_worker_1 = __importDefault(require("./implementation.tiny-worker"));
const implementation_worker_threads_1 = __importStar(require("./implementation.worker_threads"));
const runningInNode = typeof process !== 'undefined' && process.arch !== 'browser' && 'pid' in process;
function selectNodeImplementation() {
try {
return require("./implementation.worker_threads").default;
implementation_worker_threads_1.testImplementation();
return implementation_worker_threads_1.default;
}
catch (error) {
return require("./implementation.tiny-worker").default;
return implementation_tiny_worker_1.default;
}
}
exports.default = typeof process !== 'undefined' && process.arch !== 'browser' && 'pid' in process
exports.default = runningInNode
? selectNodeImplementation()
: require('./implementation.browser').default;
: implementation_browser_1.default;

@@ -7,1 +7,2 @@ declare const _default: {

export default _default;
export declare function testImplementation(): void;
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const WorkerThreads = __importStar(require("../worker_threads"));
const worker_threads_1 = __importDefault(require("../worker_threads"));
function assertMessagePort(port) {

@@ -18,9 +14,10 @@ if (!port) {

const isWorkerRuntime = function isWorkerRuntime() {
return !WorkerThreads.isMainThread;
return !worker_threads_1.default().isMainThread;
};
const postMessageToMaster = function postMessageToMaster(data, transferList) {
assertMessagePort(WorkerThreads.parentPort).postMessage(data, transferList);
assertMessagePort(worker_threads_1.default().parentPort).postMessage(data, transferList);
};
const subscribeToMasterMessages = function subscribeToMasterMessages(onMessage) {
if (!WorkerThreads.parentPort) {
const parentPort = worker_threads_1.default().parentPort;
if (!parentPort) {
throw Error("Invariant violation: MessagePort to parent is not available.");

@@ -32,5 +29,5 @@ }

const unsubscribe = () => {
assertMessagePort(WorkerThreads.parentPort).off("message", messageHandler);
assertMessagePort(parentPort).off("message", messageHandler);
};
assertMessagePort(WorkerThreads.parentPort).on("message", messageHandler);
assertMessagePort(parentPort).on("message", messageHandler);
return unsubscribe;

@@ -43,1 +40,6 @@ };

};
function testImplementation() {
// Will throw if `worker_threads` are not available
worker_threads_1.default();
}
exports.testImplementation = testImplementation;

@@ -141,5 +141,26 @@ "use strict";

exports.expose = expose;
process.on("uncaughtException", (error) => {
// Post with some delay, so the master had some time to subscribe to messages
setTimeout(() => postUncaughtErrorMessage(error), 250);
});
if (typeof self !== "undefined" && typeof self.addEventListener === "function") {
self.addEventListener("error", event => {
// Post with some delay, so the master had some time to subscribe to messages
setTimeout(() => postUncaughtErrorMessage(event.error), 250);
});
self.addEventListener("unhandledrejection", event => {
const error = event.reason;
if (error && typeof error.message === "string") {
// Post with some delay, so the master had some time to subscribe to messages
setTimeout(() => postUncaughtErrorMessage(error), 250);
}
});
}
if (typeof process !== "undefined") {
process.on("uncaughtException", (error) => {
// Post with some delay, so the master had some time to subscribe to messages
setTimeout(() => postUncaughtErrorMessage(error), 250);
});
process.on("unhandledRejection", (error) => {
if (error && typeof error.message === "string") {
// Post with some delay, so the master had some time to subscribe to messages
setTimeout(() => postUncaughtErrorMessage(error), 250);
}
});
}
{
"name": "threads",
"version": "1.0.0-beta-esm",
"version": "1.0.0-beta-esm.1",
"description": "Easy to use, yet powerful multi-threading library for node.js, web browsers and Electron",
"main": "dist/index.js",
"module": "dist-es/index.js",
"module": "dist-esm/index.js",
"scripts": {
"prebuild": "rimraf dist/ dist-es/",
"prebuild": "rimraf dist/ dist-esm/",
"build": "run-p build:cjs build:es",
"build:cjs": "tsc -p tsconfig.json",
"build:es": "tsc -p tsconfig-es.json",
"build:es": "tsc -p tsconfig-esm.json",
"pretest": "babel --plugins @babel/plugin-transform-typescript --plugins @babel/plugin-transform-modules-commonjs ./test/workers -d ./test/workers -x .ts",

@@ -72,2 +72,3 @@ "test": "run-s test:ava test:puppeteer:basic test:puppeteer:webpack",

"typescript": "^3.4.5",
"wavy": "^1.0.4",
"webpack": "^4.32.2",

@@ -98,11 +99,12 @@ "worker-plugin": "^3.1.0"

"worker_threads": false,
"./dist/master/implementation": "./dist/master/implementation.browser.js",
"./dist/master/implementation.node.js": false,
"./dist/worker/implementation": "./dist/worker/implementation.browser.js",
"./dist/worker/implementation.tiny-worker.js": false,
"./dist/worker/implementation.worker_threads.js": false
"./dist/worker/implementation.worker_threads.js": false,
"./dist-esm/master/implementation.node.js": false,
"./dist-esm/worker/implementation.tiny-worker.js": false,
"./dist-esm/worker/implementation.worker_threads.js": false
},
"files": [
"dist/**",
"dist-es/**",
"dist-esm/**",
"*.js",

@@ -109,0 +111,0 @@ "*.ts"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc