JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 28984
  • Score
    100M100P100Q142509F
  • License BSD-3-Clause

Transform async functions to generator functions with speed and simplicity.

Package Exports

  • async-to-gen
  • async-to-gen/register

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (async-to-gen) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

async-to-gen

npm Build Status

Turn your JavaScript with async functions into ES6 generators so they can be used in modern browsers or in node.js (v0.12 or newer).

Async functions are an exciting new proposed addition to JavaScript. The v8 team is hard at work getting it right, which means it could appear in future versions of node.js. However if you're impatient like me, then you probably just can't wait to get rid of your promise triangles and callback hell.

You can use Babel to accomplish this, but async-to-gen is a faster, simpler, zero-configuration alternative with minimal dependencies for super-fast npm install and transform time.

Get Started!

Use the command line:

npm install --global async-to-gen
async-to-gen --help
async-to-gen input.js > output.js

Or the JavaScript API:

npm install async-to-gen
var asyncToGen = require('async-to-gen');
var fs = require('fs');

var input = fs.readFileSync('input.js', 'utf8');
var output = asyncToGen(input);
fs.writeFileSync('output.js', output);

Use async-node

Wherever you use node you can substitute async-node and have a super fast async functions aware evaluator or REPL.

$ async-node
> async function answer() {
... return await 42
... }
undefined
> promise = answer()
Promise { <pending> }
> promise.then(console.log)
Promise { <pending> }
42

Use the require hook

Using the require hook allows you to automatically compile files on the fly when requiring in node:

require('async-to-gen/register')
require('./some-module-with-async-functions')

Dead-Simple Transforms

When async-to-gen transforms async functions, it does not affect the location of lines in a file, leading to easier to understand stack traces when debugging.

It also includes a very small (236 byte) conversion function at the bottom of the file.

Before:

async function foo() {
  return await x
}

After:

function foo() {return __async(function*(){
  return yield x
})}

function __async(f){/* small helper function */}