Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created July 18, 2014 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barneycarroll/6d5e08ea4f0bac9c4221 to your computer and use it in GitHub Desktop.
Save barneycarroll/6d5e08ea4f0bac9c4221 to your computer and use it in GitHub Desktop.
Use generators as asynchronous flow controllers (that look synchronous). Pass in a generator. It will be immediately invoked with a `callback` argument that can be inserted into asynchronous yield operations to send the response value back to the yield and resume generator execution.
function yieldBack( generator ){
return generator( function( response ){
generator.send( response.value );
} );
}
module && module.exports = yieldBack;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment