ei-queue-promise
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

ei-queue-promise

License: MIT

Statements Branches Functions Lines
Statements Branches Functions Lines

Installation

for NPM:

$ npm install ei-queue-promise -S

for YARN:

$ yarn add ei-queue-promise

Importing

ES5

var eiQueuePromise = require("ei-queue-promise");

ES6

import eiQueuePromise from "ei-queue-promise";

Sample Usage

import eiQueuePromise from "ei-queue-promise";

const promiseTestSuccessNoParam = function(_previousResult) {
  return new Promise<string>(async resolve => {
    await sleep(200);
    resolve('promiseTestSuccess');
  });
};

const promiseTestSuccessWithParam = function(
  value,
  _previousResult,
): Promise<any> {
  return new Promise<string>(async resolve => {
    await sleep(200);
    resolve(value);
  });
};

const promiseTestError = function(_value, _previousResult) {
  return new Promise<string>(async (_resolve, reject) => {
    await sleep(200);
    reject('promiseTestError');
  });

     const promiseFunctionList = [
      promiseTestSuccessNoParam,
      {
        fn: promiseTestSuccessWithParam,
        parameters: [1],
      },
      {
        fn: promiseTestSuccessWithParam,
        parameters: [2],
      },
      promiseTestError,
      {
        fn: promiseTestSuccessWithParam,
        parameters: [3],
      },
      promiseTestError,
    ];

  queuePromise(promiseFunctionList).then((result)=>{
      //result
      /*
        [
            ['promiseTestSuccess'],
            [1],
            [2],
            [null, 'promiseTestError'],
            [3],
            [null, 'promiseTestError'],
        ]
    */
  })

};

Delay

if you want to leave a delay between each queue item, you can set a delay(milliseconds) in the options.

    queuePromise([promiseTestSuccessNoParam, promiseTestSuccessNoParam], {
      debounce: 300,
    });

Logging

if you want to log the result of each queue, you can set true to the enableLog

    queuePromise([promiseTestSuccessNoParam, promiseTestSuccessNoParam], {
      enableLog: true,
    });

Package Sidebar

Install

npm i ei-queue-promise

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

5.65 kB

Total Files

3

Last publish

Collaborators

  • eijs