mul-promise
v0.0.1
Published
simple package allow run promises in multi-flow fashion
Downloads
11
Maintainers
Readme
mul-promise
simple package allow run promises in mul-flow fashion
https://tachibana-shin.github.io/mul-promise
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)
})
}
)