-
-
Notifications
You must be signed in to change notification settings - Fork 41
Doesn't allow to get a final result of an async function #45
Comments
Thanks for your report. I'm afraid I can't reproduce it. Did you include babel-preset-es2015? It's a requirement when using other ES6/7 features as mentioned in the README file: npm i babel-cli babel-plugin-async-to-promises babel-preset-es2015
marten@procyon:~/Bureaublad/testcase$ ./node_modules/.bin/babel --plugins async-to-promises --presets es2015 src.js -o index.js
marten@procyon:~/Bureaublad/testcase$ cat index.js
"use strict";
var delay = function delay(time, value) {
return new Promise(function (resolver, rejecter) {
return setTimeout(function () {
return resolver(value);
}, time);
});
};
var f = function f(x, y, z) {
var a, b, c;
return Promise.resolve().then(function () {
return delay(1000, x);
}).then(function (_resp) {
a = _resp;
console.log(a);
return delay(2000, y);
}).then(function (_resp) {
b = _resp;
console.log(b);
return delay(3000, z);
}).then(function (_resp) {
c = _resp;
console.log(c);
return a + b + c;
});
};
f(100, 200, 300).then(function (sum) {
return console.log("Sum of two arguments is " + sum);
});
marten@procyon:~/Bureaublad/testcase$ node index.js
100
200
300
Sum of two arguments is 600
marten@procyon:~/Bureaublad/testcase$ |
Did you mean that I need http://babeljs.io/docs/plugins/transform-regenerator/ ? But maybe it will be works without this module? For example I can use http://babeljs.io/docs/plugins/transform-async-to-generator/ or http://babeljs.io/docs/plugins/transform-async-to-module-method/ with |
No, regenerator isn't necessary, but babel-preset-es2015 is. I can't reproduce the rest of Babel in this module, so this module only accepts ES5 with the addition of async/await. If your code isn't ES5, downcompile it by enabling that preset. |
Hallo, im getting the same behavior. i looked into the generated code and there is a |
sorry, should have posted it in #21 ps: it would be nice if it would use the babel-runtime (if enabled) Promise and not rely on a global Promise. |
If you use babel-runtime, its Promise is the global Promise. |
I have no idea what you meant by that. kneden is using the global Promise: https://ipfs.io/ipfs/QmTCvF2Ki7SHPUAABHpQZ8HavWkAvooUZbFmy3Qjz4WrDs the issue is maybe that kneden is executed after babel-tranform-runtime
|
Any movement on this issue? |
Hello @marten-de-vries I have some experiments with your plugin and I found it interesting, but I have some cases when I don't get that I expected. For example I should to get sum of 100, 200, 300 but I cannot to get it.
The text was updated successfully, but these errors were encountered: