Skip to content
GeeksSmith

Implement Custom Promise Polyfill (Promises/A+ Microtask Chaining)

Problem Statement

Implement a custom `MyPromise` class from scratch supporting constructor executor, `.then()`, `.catch()`, chaining, and asynchronous microtask execution.

Target Complexity

Time:

O(1) resolve/reject dispatch

Space:

O(N) for callback subscriber queues

Interview Talking Points:
  • Explain the 3 Promise states: 'pending', 'fulfilled', and 'rejected' (transitions are one-way and immutable).
  • Explain why `.then()` returns a NEW Promise instance rather than returning `this` (enabling independent branches and value transformation).
Solution Editor (JavaScript)
Ready to run
Test Results
Resolves asynchronously and chains values through .then()
Test #1
Propagates errors to .catch() handler
Test #2