DEV Community

Discussion on: Using JavaScript Promises for Non-Async Control Flow?

Collapse
 
manigandham profile image
Mani Gandham

This is reasonable. The separate functions get queued as microtasks in the event loop and will probably complete in the same loop depending on how fast they return. The overhead of a Promise is minimal and modern javascript engines (if you're running this in a browser) are already well optimized for it.

The downside is you may need to continue using Promises if you want to deal with the result of the entire chain inline with other stuff, or you can just use an await at the beginning.

Collapse
 
dmerand profile image
Donald Merand

This is a good point - once you start promising you can't stop! Thanks for pointing that out - it's definitely helpful to keep in mind.

I haven't done speed tests, but I've run tests to see if I can get promises in a chain to run out of order, and I haven't found a way to break it yet. Admittedly, I'm no JavaScript hacker, but I'm generally pleased with the approach thus far.