babel-plugin-transform-async-to-bluebird
This plugin transforms async
to bluebird
.
Examples
An async function containing no await gets wrapped by bluebirds method function without using the generator, resulting in less overhead. All returned or thrown values are wrapped by Promises and then returned.
{ if input === 0 throw 'Invalid input'; if input === 42 return ; return input + 10;} ; // Returns a Promise, rejecting into an TypeError('Invalid input'); // Returns a Promise; // Returns a Promise, resolving into $other_value + 10
On the other side an async + await function gets wrapped by bluebirds coroutine; it's using the generator.
{ if input === 0 throw 'Invalid input'; const res = await ; return res + 10;}
Usage
- Install bluebird:
npm install --save bluebird
- Install the plugin:
npm install --save-dev babel-plugin-transform-async-to-bluebird
- Add transform-async-to-bluebird to your .babelrc file:
Credits
This babel plugin is based on babel-helper-remap-async-to-generator