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

node-multitask

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-multitask - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

42

dist/worker.js

@@ -19,27 +19,29 @@ "use strict";

const receive = { type: 1 /* receive */, time: Date.now(), payload };
let timer;
const start = { type: 2 /* start */, time: Date.now(), payload };
process.send(receive);
process.send(start);
const work = Promise.race([
new Promise((resolve, reject) => {
try {
const result = require(payload.work)(payload.data);
if (result instanceof Promise || typeof result.then === 'function') {
result.then(r => resolve(r));
}
else {
resolve(result);
}
}
catch (e) {
reject(e);
}
}),
new Promise((_, reject) => setTimeout(() => reject(new Error(`Task ${message.payload.uuid} is timeout \n Start Time: ${start.time}\n Worker file: ${payload.work}\n Worker data: ${payload.data}`)), timeout)),
]);
try {
const start = { type: 2 /* start */, time: Date.now(), payload };
process.send(start);
let result;
timer = setTimeout(() => {
payload.error = objectifyError(new Error(`Task ${message.payload.uuid} is timeout \n Start Time: ${start.time}\n Worker file: ${payload.work}\n Worker data: ${payload.data}`));
const finish = { type: 3 /* finish */, time: Date.now(), payload, willExit: true };
process.send(finish);
process.exit(1);
}, timeout);
result = require(payload.work)(payload.data);
if (result instanceof Promise || typeof result.then === 'function') {
result = yield result;
}
clearTimeout(timer);
payload.result = result;
const finish = { type: 3 /* finish */, time: Date.now(), payload };
process.send(finish);
payload.result = yield work;
}
catch (error) {
clearTimeout(timer);
console.error(error);
payload.error = objectifyError(error);
}
finally {
const finish = { type: 3 /* finish */, time: Date.now(), payload };

@@ -46,0 +48,0 @@ process.send(finish);

{
"name": "node-multitask",
"version": "0.3.0",
"version": "0.3.1",
"description": "A simple multi-core task runner",

@@ -19,3 +19,3 @@ "main": "dist/index.js",

"devDependencies": {
"@types/node": "^7.0.5",
"@types/node": "^7.0.8",
"@types/uuid": "^2.0.29",

@@ -22,0 +22,0 @@ "typescript": "^2.2.1"

const { MultiTask } = require('../dist/index');
const m = new MultiTask({ thread: 2, maxTimeout: 1000 * 3 });
const m = new MultiTask({ thread: 2, maxTimeout: 1000 * 3 *10 });
m.runTask({ __dirname, work: './task', data: 'hello', timeout: 1000 * 2 }).then(console.log).catch((e) => console.error(e));

@@ -5,0 +5,0 @@ m.runTask({ __dirname, work: './task', data: 'world' }).then(console.log).catch((e) => console.error(e));

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