New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

asynque

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asynque

Simple queue handling asynchronous tasks.

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

asynque

Simple queue handling asynchronous tasks.

Installation

npm i asynque

Quick Start

const { AsynQue, Task } = require('asynque');


const queue = new AsynQue();
const retrieveHello = new Task({ task: name => `Hello, ${name}!` });

queue.enque(retrieveHello).then(result => {
  console.log(`The task is done: ${result}`);
  // > The task is done: Hello, AsynQue!
});

// ... do some works, and later ...

const task = queue.deque();
const result = task.run('AsynQue');    // The promise will resolve at this moment.
// > Hello, AsynQue!

Task Priority

const { AsynQue, Task } = require('asynque');


const queue = new AsynQue();
queue.enque(new Task({ task: () => 'Run this after.', priority: 10}));
queue.enque(new Task({ task: () => 'Run this first!', priority: -10}));

console.log(queue.deque().run());   // > Run this first!
console.log(queue.deque().run());   // > Run this after.

Error Handling

const { AsynQue, Task } = require('asynque');


const queue = new AsynQue();
const taste = new Task({
  task: flavor => {
    if (flavor === 'Mint') {
      throw new Error('I hate mint');
    }

    return `It is ${flavor} flavor!`;
  },
});

queue.enque(taste)
  .then(result => {
    console.log(result);    // It's not executed because the error is thrown.
  })
  .catch(error => {
    console.error(error);
    // > I hate mint
  });

// ... do some works, and later ...

const task = queue.deque();

try {
  task.run('Mint');   // The promise will reject at this moment.
} catch (error) {
  console.error(error);
  // > Error: I hate mint
}

Keywords

queue

FAQs

Package last updated on 18 Aug 2019

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