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

0.0.1 • Public • Published

mul-promise

simple package allow run promises in mul-flow fashion

https://tachibana-shin.github.io/mul-promise

Build NPM Size Languages License Star Download

Installation

NPM / Yarn / Pnpm

pnpm add mul-promise

CDN:

<script src="https://unpkg.com/"></script>

Usage

import multiPromise from "mul-promise"


// eslint-disable-next-line no-redeclare
function multiPromise<DataTasks extends unknown[], ResultTask = unknown>(
  dataForTasks: DataTasks, // data for create tasks
  createTask: <Index extends number>(
    data: DataTasks[Index],
    index: Index
  ) => Promise<ResultTask>, // function create task
  concurrent = 5, // count task concurrent run
  onTaskDone?: (resultTask: ResultTask, index: number) => Promise<ResultTask>, // on one task done
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  onTaskError?: (error: any, index: number) => Promise<ResultTask>, // on one task error
  skipError?: boolean // no stop tasks on error
): Promise<(ResultTask | null)[]>

Example

import multiPromise from "mul-promise"

await multiPromise(
  ["Hello World", "Koniichiwa", "Ohayo", "Yahalo", "Kobanwa"],
  (message) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve(message)
      }, 1000)
    })
  }
)

Package Sidebar

Install

npm i mul-promise

Weekly Downloads

2

Version

0.0.1

License

MIT

Unpacked Size

12.6 kB

Total Files

7

Last publish

Collaborators

  • tachibana-shin