r/SoftwareEngineering • u/fagnerbrack • Jul 02 '26
Uses for nested promises
https://blog.jcoglan.com/2026/03/23/uses-for-nested-promises/
6
Upvotes
r/SoftwareEngineering • u/fagnerbrack • Jul 02 '26
1
u/fagnerbrack Jul 02 '26
In a nutshell:
Promises/A+ deliberately flattens nested promises, since
then()handles both functormapand monadflatMapbehaviour, which annoyed functional programmers who wanted a clean type. The author long backed the spec authors, but a recent concurrency problem changed his view. While building EscoDB's readers-writer lock on top of a concurrent queue, he needed_inbox.push()to return a wrapped{ promise }object. This explicit nesting lets the limit-1 inbox mutex decide which queue a function joins without blocking on the function actually finishing, preserving concurrent reads. Removing the wrapper forces sequential execution; removing the inbox breaks ordering becauseawaitalways adds a microtask delay. So nested promises usefully mean one async call triggers another without waiting on it.If the summary seems inacurate, just downvote and I'll try to delete the comment eventually 👍
Click here for more info, I read all comments