Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/unjs/items-promise
Bare minimum async methods using promises
https://github.com/unjs/items-promise
async await node parallel promise serial
Last synced: 3 months ago
JSON representation
Bare minimum async methods using promises
- Host: GitHub
- URL: https://github.com/unjs/items-promise
- Owner: unjs
- License: mit
- Created: 2017-09-03T10:57:15.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-04-29T10:16:49.000Z (9 months ago)
- Last Synced: 2024-11-11T19:00:02.956Z (3 months ago)
- Topics: async, await, node, parallel, promise, serial
- Language: JavaScript
- Size: 66.4 KB
- Stars: 55
- Watchers: 3
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# items-promise
Bare minimum async methods using promises. (Inspired by [items](https://www.npmjs.com/package/items))```bash
>_ yarn add items-promise
```OR using NPM
```bash
>_ npm install items-promise
``````js
const { serial, parallel } = require('items-promise')
// OR
import { serial, parallel } from 'items-promise'
```# Usage
`tasks` should be always an array and `fn` should be a function witch returns a **Promise** object.## serial(tasks, fn)
Run tasks one by one by calling `fn(task, previous)` in a promise chain.
Return value is of type `Promise<*>` which resolves to the **last** fn result.
## parallel(tasks, fn)
Run all tasks in parallel by calling `fn(tasks)` and await using `Promise.all`.
Return value is of type `Promise<*[]>` which resolves to results of **all** fns in an array.
# License
Released under The MIT [LICENSE](./LICENSE)Copyright (c) 2017 Pooya Parsa