Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hokaccha/node-await-flow
A simple async/await module, abstraction of node-fibers.
https://github.com/hokaccha/node-await-flow
Last synced: about 2 months ago
JSON representation
A simple async/await module, abstraction of node-fibers.
- Host: GitHub
- URL: https://github.com/hokaccha/node-await-flow
- Owner: hokaccha
- License: mit
- Created: 2013-04-04T12:34:36.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-04-10T08:07:59.000Z (over 11 years ago)
- Last Synced: 2024-04-14T09:25:36.674Z (9 months ago)
- Language: JavaScript
- Size: 121 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-await-flow
A simple async/await module, abstraction of node-fibers.
similar to
* [synchronize](https://github.com/alexeypetrushin/synchronize)
* [asyncblock](https://github.com/scriby/asyncblock)## Usage:
basic
```javascript
var AwaitFlow = require('await-flow');
var fs = require('fs');AwaitFlow.run(function(await) {
// read file async
var content = await(function(next) {
fs.readFile('./package.json', 'utf8', next);
});// wait 1000ms
await(function(next) {
setTimeout(next, 1000);
});// output file content
console.log(content);
});
```error handling
```javascript
var AwaitFlow = require('await-flow');
var fs = require('fs');AwaitFlow.run(function(await) {
var content = await(function(next) {
// not exists file
fs.readFile('/foo/bar/baz', 'utf8', next);
});console.log(content); // This line will not be executed
}, function(err) {
console.log(err);
//=> { [Error: ENOENT, open '/foo/bar/baz'] errno: 34, code: 'ENOENT', path: '/foo/bar/baz' }
});
```