babel-plugin-bluebird-async-functions
Convert async methods into Bluebird's Coroutine and Method helpers by wrapping methods marked as 'async' with the Promise.method
method, and async methods containing 'await' expressions with the Promise.coroutine
.
Dependencies
This plugin requires the babel-plugin-syntax-async-functions
plugin to be loaded before it in order for Babel to properly parse async method definitions.
Installation
Install with NPM:
npm install babel-plugin-bluebird-async-functions
Reference this plugin (with the babel-plugin-syntax-async-functions
plugin first) in your .babelrc file:
Example
sample.js
// async method async { return Promise; } // async generator async { let datas = ; for let i = 0; i < 10; i++ let datum = await Promise; datas; return datas; }
babel sample.js
:
"use strict"; var { /* Babel create class method */ }; { /* Babel class check stuff */ } var { { ; } ; return MyClass;};
Worth Mentioning
For browser use, ensure that the Bluebird library is loaded (for obvious reasons), and in a Node environment that it has been loaded globablly or within the current script.