https://github.com/mixmaxhq/synchronize-helpers
This module provides helpers for wrapping sync.defer() for synchronize.js.
https://github.com/mixmaxhq/synchronize-helpers
unsupported
Last synced: 3 months ago
JSON representation
This module provides helpers for wrapping sync.defer() for synchronize.js.
- Host: GitHub
- URL: https://github.com/mixmaxhq/synchronize-helpers
- Owner: mixmaxhq
- License: mit
- Created: 2016-08-10T13:56:33.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-08-09T19:54:50.000Z (almost 2 years ago)
- Last Synced: 2025-02-13T14:45:23.781Z (3 months ago)
- Topics: unsupported
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## synchronize-helpers
[](https://travis-ci.org/mixmaxhq/synchronize-helpers)
This module provides helpers for wrapping `sync.defer()` for `synchronize.js`.
`wrapException` is used to ensure that we won't throw an exception in a
`sync.parallel` block which would otherwise halt processing of the block.
While `swallowException` is useful to swallow any exceptions that would
otherwise be thrown (when we'd rather handle the returned data as undefined
vs try/catch which can be useful if in a `sync.parallel` block where we
expect certain errors can occur).## Install
```
$ npm install synchronize-helpers
```
or
```
$ npm install synchronize-helpers --save
```## API
### wrapException(done, errArray)
A common pattern is to use a `parallel` block from `synchronize` to run code
concurrently. `wrapException` allows you to defer error handling until the end
by providing an error to hold all exceptions that occur.```js
var sync = require('synchronize');
var wrapException = require('synchronize-helpers').wrapException;
var thrownErrors = [];sync.parallel(function() {
doA(wrapException(sync.defer(), thrownErrors));
doB(wrapException(sync.defer(), thrownErrors));
doC(wrapException(sync.defer(), thrownErrors));
});sync.await();
console.dir(thrownErrors);
```### swallowException(done)
There is also the situation where one might be retrieving data, and instead of
handling any errors, would rather consider the data to be undefined. A concrete
case would be retrieving instance metadata but not wanting to write conditional
code for determining whether the environment was production, staging, dev,
testing, etc. As such, we could do the following:```js
var sync = require('synchronize');
var swallowException = require('synchronize-helpers').swallowException;sync.parallel(function() {
doA(swallowException(sync.defer()));
doB(swallowException(sync.defer()));
doC(swallowException(sync.defer()));
});var data = sync.await();
console.dir(data);
```## Release History
* 1.0.0 Initial release.