-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Await inside for loop does not work #13
Comments
It works for me (see link below). Could it be that Please confirm and close or provide additional information. |
This function is part of an object. I will try to make a small reproducible test-case. |
Thanks. From the stack trace, it looks like it might be related to the |
@matAtWork ok, this the most minimal case that breaks:
|
Yep, that's a bug. Nodent is mangling the scope for declarations within a for-loop. I'll work on a fix. The only workaround I can suggest short-term is to use different variable names in your for loop declarations, or use 'var' since it has function scope. |
I was merely curious about nodent. Using async to bluebird coroutine works fine. I will give it another shot once the bug is fixed though. btw. will stacktraces show proper line numbers in nodent when combined with babel? |
I doubt it. Nodent's stack trace mapping is a run-time feature, which I imagine Babel mangles as the sourcemaps generated by Nodent won't make through to execution. TBH, I've not tried - it might work depending on how transparent Babel is. I've fixed the bug in Nodent v3 (not released yet), and almost back-ported it to v2.6.x but one of the main differences is how async loops are transpiled so it's a work in progress. |
Nice, I'll try it out after the release. If you generate an inline source map then babel should pick it up. |
Just published v2.6.10 which (I hope) fixes this issue. Please check on the link above. I've not updated fast-async (yet) as I'll do that when I'm ready to ship v3. You should get the update automatically if you uninstall and re-install fast-async in your project. Let me know how it goes, and thanks for the report |
It seems to have fixed it. Also, sourcemaps seem to work but they are not enabled by default. Is it a bug? I had to add the option to
async function liveBackup() {
let files = ['aaa', 'fff', 'ewrrewewrewr'];
for(let file of files) {
console.log(new Error().stack);
await Promise.resolve();
}
for(let file of files) {
await Promise.resolve();
}
return 'foo';
}
liveBackup().then(console.log); |
This is really weird. After running my test after couple minutes, the sourcemaps stopped working and then on another run they worked fine (in my small test, anyway). There is something really quirky going on. Anyway, the performance of your project is impressive but without sourcemaps this cannot be used in production. :-( |
Anyway, I'm gonna close this issue and open another one. |
This issue is still present in 2018 as of fast-async 6.3.0. |
Can you be more specific? The example given seems to transform and work fine:
|
It seems my issue is a bit different (same error, but to do with a name collision across distinct branches of an if statement where I suspect it's an interaction with another Babel plugin in our project - I'll comment back here when I've figured it out. |
Seems it was an issue with the ordering of Babel plugins in our project - having fast-async last fixed it. |
It works fine with babel's async-to-module-method.
The text was updated successfully, but these errors were encountered: