Skip to content

How to use generators to avoid passing callback functions in JavaScript

Notifications You must be signed in to change notification settings

acruikshank/hanging-up-on-callbacks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hanging-up-on-callbacks

Examples of ES6 generators:

  1. Building an iterator
  2. Passing data to a generator
  3. Suspend/resume and control flow
  4. Delegate generators
  5. Fake synchronicity ("blocking sleep()")
  6. Centralized exception handling

Punchline

sync(function* (resume) {
  console.log('foo');
  yield setTimeout(resume, 1000);
  console.log('baz');
});

console.log('blix');

// console: 'foo', 'blix', 'bax'

How to run the demo

  1. download and install Chrome Canary
  2. clone the repo
  3. bundle
  4. bundle exec ruby ./app.rb
  5. http://localhost:4567
  6. click through the examples

Inspirations

  1. Generators versus Fibers
  2. Trampolines in JavaScript
  3. ES6 Draft: Generators

About

How to use generators to avoid passing callback functions in JavaScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published