node.js - Babel transform-async-to-module-method to Bluebird with ES6 maps -
we're trying use node.js 6.5.0 babel
make async functions
use bluebird
instead of native v8 es6 promises:
our package.json
contains following babel
entries:
"devdependencies": { "babel-cli": "^6.9.0", "babel-plugin-transform-async-to-module-method": "^6.8.0", "babel-plugin-transform-es2015-destructuring": "^6.9.0", "babel-plugin-transform-es2015-modules-commonjs": "^6.14.0", }
and .babelrc
:
{ "plugins": [ "transform-es2015-modules-commonjs", "transform-es2015-destructuring", [ "transform-async-to-module-method", { "module": "bluebird", "method": "coroutine" } ] ] }
however our async functions
returning es6 map cause following error during execution:
a value [object map] yielded not treated promise
how fix this?
p.s. worked fine when async functions
transformed generators
transform-async-to-generator
here's sample code triggers same error:
function givemap() { return new map(); } void async function() { await givemap(); }();
notice givemap
isn't marked async
(which actual problem).
this code run when using transform-async-to-generator
, because map
's yieldable generators:
function* () { yield new map(); }
however, when using transform-async-to-module-method
, think code becomes similar this:
promise.coroutine(function* () { yield new map(); });
this cause error, as explained here, because promise.coroutine()
expects promises yielded.
so should on lookout functions return map
, await
'ed on, aren't mapped async
.
Comments
Post a Comment