briantford.com icon indicating copy to clipboard operation
briantford.com copied to clipboard

[article] running promises synchronously

Open btford opened this issue 10 years ago • 1 comments

via @mhevery:

Something about stack traces and running promises synchronously.

btford avatar Apr 07 '14 21:04 btford

Goal:

  • we should be able to test Async code in synchronous test.

Browser stack

  • Browser C code
  • Application

When application wants to resolve a promise it must wait until the application stack is unwound before then callback can be called. From the point of view Browser the Promise is resolved synchronously from the point of view of Application it is async.

In your tests:

  • Browser C code
  • Test harness
  • Application

There is nothing special about Browser C code to imply that that is where the sync/async boundary should be, therefore we can move the sync/async boundary between Test and Application. This allows the test to be sync but your app to be written in Async mode.

This is safe. There is no way for the app to detect that the promise is resolved as long as the async/sync boundary is above the first application stack frame.

mhevery avatar Apr 07 '14 22:04 mhevery