Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/malipetek/onebyone.js
Array.forEach replacement for async operations
https://github.com/malipetek/onebyone.js
Last synced: about 1 month ago
JSON representation
Array.forEach replacement for async operations
- Host: GitHub
- URL: https://github.com/malipetek/onebyone.js
- Owner: malipetek
- Created: 2020-02-23T12:21:11.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-08T21:19:35.000Z (over 4 years ago)
- Last Synced: 2024-03-23T10:23:32.577Z (10 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# oneByOne.js
Array.forEach replacement for async operationsoneByOne.js allows you to loop over a array and execute some async operations. Method itself returns a promise and resolves into an array of results of executions just like `Promise.all`.
Difference from `Promise.all` is, your actions are executed sequentially and you have access to previous results.
Example 1:
```js
require('onebyonejs');['a', 'b', 'c', 'd'].oneByOne(function(element, index, results, previousResult) {
return new Promise(function (done) {
fetch('www.google.com/?q=' + element)
.then(function(response) { return response.text() })
.then(function(responseText) {
done(responseText);
})
});
});
```Example 2:
```js
require('onebyonejs');['a', 'b', 'c', 'd'].oneByOne(async (element, index, results, previousResult) => {
const response = await fetch('www.google.com/?q=' + this)
const responseText = await response.text();
return responseText;
});
```
It does not export anything, so you just include it.[![Edit OneByOne.js](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/onebyonejs-dhj7k?fontsize=14&hidenavigation=1&theme=dark)