https://github.com/gemini-testing/q-promise-utils
Several promise helpers simplifying interaction with multiple async operations
https://github.com/gemini-testing/q-promise-utils
Last synced: 10 months ago
JSON representation
Several promise helpers simplifying interaction with multiple async operations
- Host: GitHub
- URL: https://github.com/gemini-testing/q-promise-utils
- Owner: gemini-testing
- License: mit
- Created: 2015-12-03T20:57:13.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2019-11-06T22:03:46.000Z (about 6 years ago)
- Last Synced: 2025-01-31T12:18:18.784Z (11 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# q-promise-utils
Several utils for simpifying interaction with multiple async operations.
## API
### utils.sequence(funcs, [args])
Executes `funcs` in async manner one by one.
Arguments:
* funcs - functions to execute
* args (optional) - arguments to pass to each function
Example:
```js
var foo = function() {},
bar = function() {};
utils.sequence([foo, bar], 'some-string', 100500)
.then(function() {
// first executed `foo('some-string', 100500)`,
// then `bar('some-string', 100500)`,
// then arrives to this code block
});
```
### utils.seqMap(items, callback)
Serially applies `callback` to each item in `items` array in async manner
Example:
```js
var items = ['foo', 'bar'],
callback = function() {};
utils.seqMap(items, callback)
.then(function() {
//first runs `callback` with arg `foo`, then with arg `bar`, next arrives to this code block
});
```
##utils.waitForResults(promises)
Waits for all promises in array to be resolved or rejected.
Unlike Q.allSettled, rejects when any of the promises is rejected.
Unlike Q.all does not immediately rejects a promise on a first error and waits for other operations to complete.
Example:
```js
var delay = q.delay(100),
rejected = q.reject('whatever');
utils.waitForResults([rejected, delay])
.fail(function(reason) {
//arrives here after 100ms with reject reason `whatever`
});
```