Skip to content
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

Using async/await with thenables (non-native promises) loses the scope #654

Closed
rochdev opened this issue Aug 20, 2019 · 2 comments · Fixed by #664
Closed

Using async/await with thenables (non-native promises) loses the scope #654

rochdev opened this issue Aug 20, 2019 · 2 comments · Fixed by #664
Assignees
Labels
bug Something isn't working

Comments

@rochdev
Copy link
Member

rochdev commented Aug 20, 2019

Describe the bug

When using async/await with thenables (non-native promises) without explicitly calling then, it causes the scope to be lost. This is because await schedules the call to then on the next tick, at which point it's called in a different context, usually the native context which always has an ID of 0.

This is a current limitation in Node which is unlikely to be resolved soon. A possible workaround is to call then before calling await, for example await request.get(url).then(x => x).

@rochdev rochdev added the bug Something isn't working label Aug 20, 2019
@rochdev rochdev self-assigned this Aug 20, 2019
@rochdev
Copy link
Member Author

rochdev commented Aug 22, 2019

@ignaciocavina Can you try with 0.15.0-beta.1 with the following option on the tracer?

tracer.init({
  experimental: {
    thenables: true
  }
})

This should fix the issue for Superagent and any other thenables by working around the limitation in Node.

@ignaciocavina
Copy link

ignaciocavina commented Aug 26, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants