polled
v1.0.2
Published
Single-shot request + polling combined into a single AsyncGenerator
Downloads
4
Readme
Polled
Single-shot request + polling combined into a single AsyncGenerator
Use case
Long-running HTTP request where the backend uploads intermediate results to a pollable endpoint
- Client: GET /server
- Server: Starts processing...
- For each result: PUT /endpoint
- Client: polls to GET /endpoint/poll
- Server returns (HTTP response)
Usage
import { polled } from 'polled'
async function* polledRequest() {
const { values, response } = polled(
fetch('/request'),
() => fetch('/endpoint/poll'),
2 // delaySecs
)
for await (const pollResult of values)
// do something with polled result
// do something with response
await response
}