Asynchronous stack traces: why await beats .then()

Insightful post by Mathias Bynens:

The fundamental difference between await and vanilla promises is that await X() suspends execution of the current function, while promise.then(X) continues execution of the current function after adding the X call to the callback chain. In the context of stack traces, this difference is pretty significant.

The gist is that when using .then(), the JS engine needs to capture the stack trace for future use in case things go awry.

Capturing the stack trace takes time (i.e. degrades performance); storing these stack traces requires memory. 🐌👎

Asynchronous stack traces: why await beats .then()

Sidenote: Need extra arguments to prefer async/await over promises? Read 6 Reasons Why JavaScript’s Async/Await Blows Promises Away.

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.