Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iso50/step-by-step
Tiny tooling to execute Promises in a synchronous manner
https://github.com/iso50/step-by-step
array async asynchronous es6 javascript library promise synchronous
Last synced: 7 days ago
JSON representation
Tiny tooling to execute Promises in a synchronous manner
- Host: GitHub
- URL: https://github.com/iso50/step-by-step
- Owner: ISO50
- Created: 2017-02-19T11:17:23.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-04-09T02:02:12.000Z (over 2 years ago)
- Last Synced: 2023-08-16T21:33:03.338Z (about 1 year ago)
- Topics: array, async, asynchronous, es6, javascript, library, promise, synchronous
- Language: JavaScript
- Size: 138 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# step-by-step
A simple way to execute a group of ES6 promises in a synchronous manner.
## How to use
In this example a synthetic `Promise` is used to show how `runSync` works.
The input array for runSync should contain functions which return the Promises that will be executed in a synchronous way.```javascript
const runSync = require('step-by-step').runSync;const createPromise = (param) => {
return () => {
return new Promise(resolve => {const [planet, stopFor] = param;
setTimeout(() => {
console.log(planet);
resolve(planet);
}, stopFor);
});
};
};const promiseArray = [
createPromise(['Mercury', 220]),
createPromise(['Venus', 100]),
createPromise(['Earth', 1]),
createPromise(['Mars', 150])
];// Output: Mercury, Venus, Earth, Mars
const results = runSync(promiseArray);// Output: [ 'Mercury', 'Venus', 'Earth', 'Mars' ]
results.then(console.log);
```Looks a bit bulky? If all the promise factory related stuff is left out it looks way cleaner:
```javascript
const runSync = require('step-by-step').runSync;const promises = [
() => fetch('http://a'),
() => fetch('http://b'),
() => fetch('http://c')
];runSync(promises);
```## Changelog
* `1.0.8` - updated dev dependencies
* `1.0.6` - changed typings
* `1.0.4` - fix wrong export 😀
* `1.0.2` - add typings see #1