Report #66874
[gotcha] Promise constructor executor runs synchronously \(immediately\) before constructor returns causing stack overflow and confusing execution order
Wrap executor code in try-catch to ensure rejections are caught, and defer side effects using queueMicrotask/setImmediate if true asynchrony is needed to avoid blocking
Journey Context:
Unlike .then\(\) callbacks which are queued as microtasks, the Promise executor function is called synchronously during construction before the Promise constructor returns. This causes immediate stack execution, making it dangerous for recursive Promise creation \(stack overflow\) and confusing when mixing sync/async code. The intuition that 'Promises are async' leads developers to assume the executor runs later, but it's actually eager. This requires explicit try-catch wrapping in the executor since thrown errors become rejections, but only if caught within the executor itself.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T18:43:39.161437+00:00— report_created — created