@brainsights/promise-task
Advanced tools
Comparing version 2.0.0 to 2.1.0
30
index.js
@@ -42,3 +42,3 @@ const EventEmitter = require("events") | ||
if(progress !== value) { | ||
__.get(task).progress = value; | ||
__.get(task).progress = toPercent(value); | ||
task.emit("progress", value); | ||
@@ -52,3 +52,4 @@ } | ||
__.get(task).onCancel = () => { | ||
cb.call(this); | ||
if(cb) | ||
cb.call(this); | ||
this.reject(new Error("canceled")); | ||
@@ -106,3 +107,3 @@ } | ||
{ | ||
if(__.get(this).isRunning) { | ||
if(__.get(this).isRunning) { | ||
__.get(this).onCancel.call(this); | ||
@@ -125,3 +126,3 @@ __.get(this).isCanceled = true; | ||
{ | ||
return new this.constructor(__.get(this).executor); | ||
return new Task(__.get(this).executor); | ||
} | ||
@@ -132,10 +133,21 @@ | ||
let batch = new Task(async (context) => { | ||
for(let task of tasks) { | ||
let results = []; | ||
let canceled = false; | ||
for(let i = 0; i < tasks.length && !canceled; ++ i) { | ||
let task = tasks[i]; | ||
task.on("progress", () => { | ||
context.progress(toPercent( | ||
_.sum(_.map(tasks, (item) => item.progress()))/tasks.length | ||
)); | ||
context.progress(_.sum(_.map(tasks, (item) => item.progress()))/tasks.length); | ||
}); | ||
await task.run(); | ||
context.onCancel= () => { | ||
canceled = true; | ||
task.cancel | ||
}; | ||
try { | ||
results[i] = await task.run(); | ||
} catch(e) { | ||
return context.reject(e); | ||
} | ||
} | ||
context.resolve(results); | ||
}); | ||
@@ -142,0 +154,0 @@ |
{ | ||
"name": "@brainsights/promise-task", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Lazy promises with support for cancellation and progress events", | ||
@@ -16,4 +16,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"@brainsights/uuid": "1.1.0", | ||
"lodash": "^4.17.5" | ||
} | ||
} |
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
5255
136
2
+ Added@brainsights/uuid@1.1.0
+ Added@brainsights/uuid@1.1.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbrowser-stdout@1.3.0(transitive)
+ Addedcommander@2.9.0(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedd64@1.0.0(transitive)
+ Addeddebug@2.6.82.6.9(transitive)
+ Addeddiff@3.2.0(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.1.1(transitive)
+ Addedgraceful-readlink@1.0.1(transitive)
+ Addedgrowl@1.9.2(transitive)
+ Addedhas-flag@1.0.0(transitive)
+ Addedhe@1.1.1(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedjson3@3.3.2(transitive)
+ Addedlodash._baseassign@3.2.0(transitive)
+ Addedlodash._basecopy@3.0.1(transitive)
+ Addedlodash._basecreate@3.0.3(transitive)
+ Addedlodash._getnative@3.9.1(transitive)
+ Addedlodash._isiterateecall@3.0.9(transitive)
+ Addedlodash.create@3.1.1(transitive)
+ Addedlodash.isarguments@3.1.0(transitive)
+ Addedlodash.isarray@3.0.4(transitive)
+ Addedlodash.keys@3.1.2(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@0.0.8(transitive)
+ Addedmkdirp@0.5.1(transitive)
+ Addedmocha@3.5.3(transitive)
+ Addedms@2.0.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedshould@11.2.1(transitive)
+ Addedshould-equal@1.0.1(transitive)
+ Addedshould-format@3.0.3(transitive)
+ Addedshould-type@1.4.0(transitive)
+ Addedshould-type-adaptors@1.1.0(transitive)
+ Addedshould-util@1.0.1(transitive)
+ Addedsupports-color@3.1.2(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedwrappy@1.0.2(transitive)