# PriorityQueue

class in `3d-tiles-renderer/core`

```js
import { PriorityQueue } from '3d-tiles-renderer/core';
```

Priority queue for scheduling async work with a concurrency limit. Items are
sorted by `priorityCallback` and dispatched up to `maxJobs` at a time.

## Properties

### .running: boolean

readonly

returns whether tasks are queued or actively running

### .maxJobs: number

default `6`

Maximum number of jobs that can run concurrently.

### .autoUpdate: boolean

default `true`

If true, job runs are automatically scheduled after `add` and after each job completes.

### .priorityCallback: PriorityCallback | null

default `null`

Comparator used to sort queued items. Higher-priority items should sort last
(i.e. return positive when `itemA` should run before `itemB`).

## Methods

### .sort

```js
.sort(  )
```

Sorts the pending item list using `priorityCallback`, if set.

### .has

```js
.has( item: any ): boolean
```

Returns whether the given item is currently queued.

- `item`, `any`

### .add

```js
.add( item: any, callback: ItemCallback ): Promise<any>
```

Adds an item to the queue and returns a Promise that resolves when the item's
callback completes, or rejects if the item is removed before running.

- `item`, `any`
- `callback`, `ItemCallback`: Invoked with `item` when it is dequeued; may return a Promise

### .remove

```js
.remove( item: any )
```

Removes an item from the queue, rejecting its promise with an `AbortError` DOMException.

- `item`, `any`

### .removeByFilter

```js
.removeByFilter( filter: FilterCallback )
```

Removes all queued items for which `filter` returns true.

- `filter`, `FilterCallback`: Called with each item; return true to remove

### .tryRunJobs

```js
.tryRunJobs(  )
```

Immediately attempts to dequeue and run pending jobs up to `maxJobs` concurrency.

### .flush

```js
.flush( item: any ): Promise<any> | any
```

Immediately runs the callback for the given item, removing it from the queue.
Does nothing if the item is not queued.

- `item`, `any`

### .scheduleJobRun

```js
.scheduleJobRun(  )
```

Schedules a deferred call to `tryRunJobs` via `schedulingCallback`.
