liveBook · Manning

Pull model

As explained in The Joy of JavaScript

A communication or data-flow model in which a consumer requests data when it needs it.

The pull model makes the consumer initiate every request for data. A producer may be a function or another data source, but it does not know when data is needed; the consumer calls it when ready. section 9.3.1

Pull contrasts with push, where the producer controls when values arrive. In JavaScript, invoking a function or repeatedly calling an iterator’s next method are pull operations; promises and asynchronous generators represent push-oriented alternatives. section 9.3.1

Common pull forms include:

  • A function returns data when the consumer invokes it. section 9.3.1
  • An iterator supplies successive values as the consumer calls next repeatedly. section 9.3.1
  • Arrays expose pull access through indexing, methods such as indexOf, and Symbol.iterator. section 9.3.2

Polling versus notification

An array can be checked at intervals to discover whether it has changed, but that long-polling approach repeatedly picks at the data. A push design instead lets the producer notify subscribers when a value arrives. section 9.3.2

Figure 9.2 The difference between pull and push. With pull, the consumer must always initiate a request for data. With push, when the consumer subscribes, the producer sends data as it becomes available, stopping when the consumer unsubscribes or when there’s no more data to send.

Compare the direction of control: pull requires the consumer to initiate each request, while push lets the producer send values after subscription. section 9.3.1

How The Joy of JavaScript covers it

How deep it goes
Defines producer-consumer control and demonstrates functions, iterator next calls, arrays, and polling, without implementing a standalone pull abstraction.
Examples
Uses function calls, iterator next calls, array indexing, Symbol.iterator, and interval-based long polling as concrete pull examples.
What it assumes
Assumes basic producer-consumer roles and JavaScript functions, while introducing pull and push control differences.
What you can do after
Apply it via JavaScript functions, iterators, and array access when consumers should control when data is requested.
How it connects
Connects pull with producer-consumer relationships, push models, iterators, arrays, promises, asynchronous generators, and streams.

Also explained in

Compare how 4 books explain pull model →

Related concepts

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