workbox-background-sync. Queue
A class to manage storing failed requests in IndexedDB and retrying them later. All parts of the storing and replaying process are observable via callbacks.
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
|
Property
name
- Returns
-
string
Methods
getAll
getAll() returns Promise containing Array of Object
Returns all the entries that have not expired (per maxRetentionTime
).
Any expired entries are removed from the queue.
- Returns
-
Promise containing Array of Object
popRequest
popRequest() returns Promise containing Object
Removes and returns the last request in the queue (along with its
timestamp and any metadata). The returned object takes the form:
{request, timestamp, metadata}
.
- Returns
-
Promise containing Object
pushRequest
pushRequest(entry)
Stores the passed request in IndexedDB (with its timestamp and any metadata) at the end of the queue.
Parameter |
|||||||||
---|---|---|---|---|---|---|---|---|---|
entry |
Object Values in
|
registerSync
registerSync()
Registers a sync event with a tag unique to this instance.
replayRequests
replayRequests()
Loops through each request in the queue and attempts to re-fetch it. If any request fails to re-fetch, it's put back in the same position in the queue (which registers a retry for the next sync event).
shiftRequest
shiftRequest() returns Promise containing Object
Removes and returns the first request in the queue (along with its
timestamp and any metadata). The returned object takes the form:
{request, timestamp, metadata}
.
- Returns
-
Promise containing Object
unshiftRequest
unshiftRequest(entry)
Stores the passed request in IndexedDB (with its timestamp and any metadata) at the beginning of the queue.
Parameter |
|||||||||
---|---|---|---|---|---|---|---|---|---|
entry |
Object Values in
|