Constructor

Queue

new Queue(name, options)

Creates an instance of Queue with the given options

Parameter

name

string

The unique name for this queue. This name must be unique as it's used to register sync events and store requests in IndexedDB specific to this instance. An error will be thrown if a duplicate name is detected.

options

Optional

Object

Values in options have the following properties:

Parameter

callbacks

Optional

Object

Callbacks to observe the lifecycle of queued requests. Use these to respond to or modify the requests during the replay process.

callbacks.requestWillEnqueue

Optional

function(StorableRequest)

Invoked immediately before the request is stored to IndexedDB. Use this callback to modify request data at store time.

callbacks.requestWillReplay

Optional

function(StorableRequest)

Invoked immediately before the request is re-fetched. Use this callback to modify request data at fetch time.

callbacks.queueDidReplay

Optional

function(Array of StorableRequest)

Invoked after all requests in the queue have successfully replayed.

maxRetentionTime

Optional

number

The amount of time (in minutes) a request may be retried. After this amount of time has passed, the request will be deleted from the queue.

Property

name

Returns

string 

Methods

addRequest

async

addRequest(request)

Stores the passed request into IndexedDB. The database used is workbox-background-sync and the object store name is the same as the name this instance was created with (to guarantee it's unique).

Parameter

request

Request

The request object to store.

replayRequests

async

replayRequests()

Retrieves all stored requests in IndexedDB and retries them. If the queue contained requests that were successfully replayed, the queueDidReplay callback is invoked (which implies the queue is now empty). If any of the requests fail, a new sync registration is created to retry again later.