
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@brainsights/promise-task
Advanced tools
Lazy promises with progress and cancelation.
npm install promise-task
Use a task anywhere you would use a promise, with a few minor changes.
const Task = require("promise-task");
let task = new Task((context) => {
let progress = 0;
let timer;
timer = setInterval(() => {
progress += 1;
if(progress >= 100) {
clearTimeout(timer);
context.progress(100);
context.resolve(true);
} else {
context.progress(progress);
}
}, 100);
context.onCancel = () => {
clearTimeout(timer);
};
});
task.on("progress", (progress) => console.log(progress));
await task.run();
Create a new task by new Task(executor).
executor (Function) accepts a single argument, context.Invoke this to begin executing the task. Returns a Promise that is resolved or rejected when the task completes.
Returns the current progress as number.
Cancels execution and rejects the associated promise.
Returns true if the task is canceled, false otherwise.
Creates a copy of a task instance.
Returns a new Task that wraps one or more tasks that are executed one-at-a-time.
tasks (Array): A list of tasks to execute in series when run() is invoked.
Task property that contains the last Error if there is one, or null.
Invoke this from the executor to resolve the associated promise.
result (Any): The successful result of the completed task.Invoke this from the exectutor to reject the associated promise.
error (Error): An error explaining why the task failed.Invoke this from the executor to update the task progress.
value: A number between 0 and 100 (inclusive).Set this property to the callback that should be invoked if the task is canceled. This property is only writable, and cannot be read.
callback (Function): A callback function invoked when Task.cancel() is called.FAQs
Lazy promises with support for cancellation and progress events
We found that @brainsights/promise-task demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.