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

@matrixai/workers

Package Overview
Dependencies
Maintainers
4
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@matrixai/workers - npm Package Compare versions

Comparing version 1.2.5 to 1.3.0

10

dist/errors.d.ts

@@ -1,6 +0,8 @@

import { CustomError } from 'ts-custom-error';
declare class ErrorWorkerManager extends CustomError {
import { AbstractError } from '@matrixai/errors';
declare class ErrorWorkerManager<T> extends AbstractError<T> {
static description: string;
}
declare class ErrorWorkerManagerNotRunning extends ErrorWorkerManager {
declare class ErrorWorkerManagerDestroyed<T> extends ErrorWorkerManager<T> {
static description: string;
}
export { ErrorWorkerManager, ErrorWorkerManagerNotRunning };
export { ErrorWorkerManager, ErrorWorkerManagerDestroyed };

12

dist/errors.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorWorkerManagerNotRunning = exports.ErrorWorkerManager = void 0;
const ts_custom_error_1 = require("ts-custom-error");
class ErrorWorkerManager extends ts_custom_error_1.CustomError {
exports.ErrorWorkerManagerDestroyed = exports.ErrorWorkerManager = void 0;
const errors_1 = require("@matrixai/errors");
class ErrorWorkerManager extends errors_1.AbstractError {
}
exports.ErrorWorkerManager = ErrorWorkerManager;
class ErrorWorkerManagerNotRunning extends ErrorWorkerManager {
ErrorWorkerManager.description = 'WorkerManager error';
class ErrorWorkerManagerDestroyed extends ErrorWorkerManager {
}
exports.ErrorWorkerManagerNotRunning = ErrorWorkerManagerNotRunning;
exports.ErrorWorkerManagerDestroyed = ErrorWorkerManagerDestroyed;
ErrorWorkerManagerDestroyed.description = 'WorkerManager is destroyed';
//# sourceMappingURL=errors.js.map

@@ -27,5 +27,3 @@ import type { ModuleThread } from 'threads';

protected logger: Logger;
protected _running: boolean;
protected _destroyed: boolean;
protected constructor({ workerFactory, cores, logger, }: {
constructor({ workerFactory, cores, logger, }: {
workerFactory: () => Promise<ModuleThread<W>>;

@@ -35,4 +33,2 @@ cores?: number;

});
get running(): boolean;
get destroyed(): boolean;
destroy({ force, }?: {

@@ -39,0 +35,0 @@ force?: boolean;

@@ -14,2 +14,8 @@ "use strict";

});
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importStar = (this && this.__importStar) || function (mod) {

@@ -25,13 +31,12 @@ if (mod && mod.__esModule) return mod;

};
var WorkerManager_1;
Object.defineProperty(exports, "__esModule", { value: true });
const threads_1 = require("threads");
const logger_1 = __importDefault(require("@matrixai/logger"));
const CreateDestroy_1 = require("@matrixai/async-init/dist/CreateDestroy");
const errors = __importStar(require("./errors"));
class WorkerManager {
let WorkerManager = WorkerManager_1 = class WorkerManager {
constructor({ workerFactory, cores, logger, }) {
this._running = false;
this._destroyed = false;
this.logger = logger;
this.pool = threads_1.Pool(workerFactory, cores);
this._running = true;
}

@@ -52,3 +57,3 @@ /**

logger.info('Creating WorkerManager');
const workerManager = new WorkerManager({
const workerManager = new WorkerManager_1({
workerFactory,

@@ -61,44 +66,36 @@ cores,

}
get running() {
return this._running;
}
get destroyed() {
return this._destroyed;
}
async destroy({ force = false, } = {}) {
if (this._destroyed) {
return;
}
this.logger.info('Destroying WorkerManager');
await this.pool.terminate(force);
this._running = false;
this._destroyed = true;
this.logger.info('Destroyed WorkerManager');
}
async call(f) {
if (!this._running) {
throw new errors.ErrorWorkerManagerNotRunning();
}
return await this.pool.queue(f);
}
queue(f) {
if (!this._running) {
throw new errors.ErrorWorkerManagerNotRunning();
}
return this.pool.queue(f);
}
async completed() {
if (!this._running) {
throw new errors.ErrorWorkerManagerNotRunning();
}
return await this.pool.completed();
}
async settled() {
if (!this._running) {
throw new errors.ErrorWorkerManagerNotRunning();
}
return await this.pool.settled();
}
}
};
__decorate([
CreateDestroy_1.ready(new errors.ErrorWorkerManagerDestroyed())
], WorkerManager.prototype, "call", null);
__decorate([
CreateDestroy_1.ready(new errors.ErrorWorkerManagerDestroyed())
], WorkerManager.prototype, "queue", null);
__decorate([
CreateDestroy_1.ready(new errors.ErrorWorkerManagerDestroyed())
], WorkerManager.prototype, "completed", null);
__decorate([
CreateDestroy_1.ready(new errors.ErrorWorkerManagerDestroyed())
], WorkerManager.prototype, "settled", null);
WorkerManager = WorkerManager_1 = __decorate([
CreateDestroy_1.CreateDestroy()
], WorkerManager);
exports.default = WorkerManager;
//# sourceMappingURL=WorkerManager.js.map

@@ -5,3 +5,5 @@ import type { ModuleThread } from 'threads';

interface WorkerManagerInterface<W extends ModuleMethods> {
destroy(): Promise<void>;
destroy(options: {
force?: boolean;
}): Promise<void>;
call<T>(f: (worker: ModuleThread<W>) => Promise<T>): Promise<T>;

@@ -8,0 +10,0 @@ queue<T>(f: (worker: ModuleThread<W>) => Promise<T>): QueuedTask<ModuleThread<W>, T>;

{
"name": "@matrixai/workers",
"version": "1.2.5",
"version": "1.3.0",
"author": "Roger Qiu",

@@ -23,5 +23,6 @@ "description": "Multithreaded Workers",

"dependencies": {
"@matrixai/async-init": "^1.7.0",
"@matrixai/logger": "^2.1.0",
"threads": "^1.6.5",
"ts-custom-error": "^3.2.0"
"@matrixai/errors": "^1.0.1",
"threads": "^1.6.5"
},

@@ -28,0 +29,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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