← Lessons

quiz vs the machine

Gold1400

Concurrency

Futures and Promises

Placeholders for values that will be available later.

4 min read · core · beat Gold to climb

Futures and Promises

A future is a placeholder for a result that is not ready yet. It represents a computation that will complete later, letting you continue work and collect the answer when needed.

A promise is the writable side. One part of the program holds the promise and eventually resolves it with a value or rejects it with an error. The matching future is the read only view that consumers await.

This split lets producers and consumers stay decoupled:

  • The consumer holds a future and registers a continuation.
  • The producer holds the promise and fulfills it when the work finishes.
  • Resolving the promise notifies everyone waiting on the future.

Futures compose. You can chain transformations so that when one completes, the next begins, building pipelines without nested callbacks. Most libraries also support combining many futures, waiting until all complete or until the first one does.

A future can be in three states: pending, fulfilled, or rejected. Once settled it never changes again.

Key idea

A promise is the writable handle a producer resolves; the future is the read only placeholder a consumer awaits and chains.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the difference between a promise and a future?

2. How many final states does a settled future have?