Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

await-task-queue

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

await-task-queue

Execute tasks consecutive while still being able to await

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

Why

Simple task queue that execute tasks consecutive but each add can be awaited to know when the added task is executed and get return data. A promise start to excecute when it is created that is why the promise itself is created by the queue.

Example

import TaskQueue from './../src/task-queue.js';
let queue = TaskQueue();

async function example() {
    queue.add((resolve) => resolve("Gris"))
        .then((res) => console.log(res));

    queue.add((resolve) => setTimeout(resolve, 200))
        .then(() => console.log("Slept for 200ms"));

    queue.add((resolve, reject) => reject("Failed"))
        .then(()=>console.log("Shall never happen") )
        .catch((e)=>console.log("Got error: ", e));

    let result = await queue.add((resolve) => resolve("Await last"));
    console.log(result);
}
example();

// Printout
// Gris
// Slept for 200ms
// Got error:  Failed
// Await last

Keywords

queue

FAQs

Package last updated on 04 Jan 2022

Did you know?

Socket

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.

Install

Related posts