Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

mfbx9da4/async-await-with-generators

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Async await implemented with generators. This code is an experiment for showing how async await could be implemented.

Thanks to Eli who originally had the idea for async await with generators before promises were a thing.

Usage

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(`<div>${url}</div>`)
  }, 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(`<div>http://url.com/${i}</div>`)
  }
}

// invoking our function with the library
lib.async(example)

Test 

npm test

About

Async await implemented with generators

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
Morty Proxy This is a proxified and sanitized view of the page, visit original site.