---
url: /api/symbols/workbox-swkit/background-sync/queue.md
---

# Queue

Class @vite-pwa/workbox-swkit/background-sync

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

```ts
new Queue(name: string, options?: QueueOptions)
```

Creates an instance of Queue with the given options

**Parameters**

* `name` – 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.

## Methods

### getAll()

```ts
getAll(): Promise<QueueEntry[]>
```

Returns all the entries that have not expired (per `maxRetentionTime`).
Any expired entries are removed from the queue.

**Returns:**

### popRequest()

```ts
popRequest(): Promise<QueueEntry | undefined>
```

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:**

### pushRequest()

```ts
pushRequest(entry: QueueEntry): Promise<void>
```

Stores the passed request in IndexedDB (with its timestamp and any
metadata) at the end of the queue.

### registerSync()

```ts
registerSync(): Promise<void>
```

Registers a sync event with a tag unique to this instance.

### replayRequests()

```ts
replayRequests(): Promise<void>
```

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()

```ts
shiftRequest(): Promise<QueueEntry | undefined>
```

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:**

### size()

```ts
size(): Promise<number>
```

Returns the number of entries present in the queue.
Note that expired entries (per `maxRetentionTime`) are also included in this count.

**Returns:**

### unshiftRequest()

```ts
unshiftRequest(entry: QueueEntry): Promise<void>
```

Stores the passed request in IndexedDB (with its timestamp and any
metadata) at the beginning of the queue.
