https://github.com/mfbx9da4/async-await-with-generators
Async await implemented with generators
https://github.com/mfbx9da4/async-await-with-generators
async asyncawait
Last synced: about 1 month ago
JSON representation
Async await implemented with generators
- Host: GitHub
- URL: https://github.com/mfbx9da4/async-await-with-generators
- Owner: mfbx9da4
- Created: 2018-02-01T00:46:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-20T06:55:32.000Z (about 2 years ago)
- Last Synced: 2025-03-28T13:21:16.805Z (about 2 months ago)
- Topics: async, asyncawait
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
Async await implemented with generators. This code is an experiment for showing how async await could be implemented.
Thanks to [Eli who originally](https://github.com/eligrey/async.js) had the idea for async await with generators before promises were a thing.
## Usage
```js
const lib = require('./lib')
// Some example asynchronous function
// The library assumes that all async funcs must have a callback as the last arg
function doGet (url, callback) {
setTimeout(() => {
callback(`${url}`)
}, 1)
}// our example function which takes await as a parameter
function * example (await) {
for (let i = 0; i < 5; i++) {
const res = yield await(doGet, [`http://url.com/${i}`]);
expect(res).to.equal(`http://url.com/${i}`)
}
}// invoking our function with the library
lib.async(example)
```## Test
npm test