liveBook · Manning

Polling

As explained in API Design Patterns

A polling loop is a repeated sequence of requests that checks an asynchronous operation until a completion condition is reached.

Polling repeatedly requests a long-running operation until its done field becomes true, then returns the operation’s final result. It is simple, timely according to the client’s schedule, and places result-checking under client control. section 10.3.3 section 10.0

Creating a chat room

A client calls CreateChatRoom, repeatedly calls GetOperation with the returned operation ID, waits one second between requests, and returns operation.result when complete.

Choose polling deliberately:

  • Use a fixed wait interval or exponential back-off to reduce unnecessary network traffic and server compute. section 10.3.3 section 10.3.3
  • Persist the operation ID so another process can resume polling after the initiating process fails. section 10.3.8
  • Prefer a custom wait method when the API can block until completion instead of requiring repeated status requests. section 10.3.3

How API Design Patterns covers it

How deep it goes
Defines the request loop, delay strategies, API methods, costs, and recovery concern without detailing transport internals.
Examples
Demonstrates CreateChatRoom, GetOperation, a one-second delay, and a chat-room result.
What it assumes
Assumes long-running operations and operation identifiers while showing the polling mechanism from its basic request sequence.
What you can do after
Apply it via GetOperation and an operation ID, then return the completed result after the done condition is reached.
How it connects
Connects long-running operations with promises, futures, exponential back-off, waiting, and operation persistence.

Also explained in

Compare how 9 books explain polling →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of API Design Patterns. The section links point to the parts of the book it draws on.