Last change
on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | /**
|
---|
2 | * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
---|
3 | *
|
---|
4 | * This source code is licensed under the MIT license found in the
|
---|
5 | * LICENSE file in the root directory of this source tree.
|
---|
6 | */
|
---|
7 | import type { QueueChildMessage, TaskQueue } from './types';
|
---|
8 | export declare type ComputeTaskPriorityCallback = (method: string, ...args: Array<unknown>) => number;
|
---|
9 | declare type QueueItem = {
|
---|
10 | task: QueueChildMessage;
|
---|
11 | priority: number;
|
---|
12 | };
|
---|
13 | /**
|
---|
14 | * Priority queue that processes tasks in natural ordering (lower priority first)
|
---|
15 | * accoridng to the priority computed by the function passed in the constructor.
|
---|
16 | *
|
---|
17 | * FIFO ordering isn't guaranteed for tasks with the same priority.
|
---|
18 | *
|
---|
19 | * Worker specific tasks with the same priority as a non-worker specific task
|
---|
20 | * are always processed first.
|
---|
21 | */
|
---|
22 | export default class PriorityQueue implements TaskQueue {
|
---|
23 | private _computePriority;
|
---|
24 | private _queue;
|
---|
25 | private _sharedQueue;
|
---|
26 | constructor(_computePriority: ComputeTaskPriorityCallback);
|
---|
27 | enqueue(task: QueueChildMessage, workerId?: number): void;
|
---|
28 | _enqueue(task: QueueChildMessage, queue: MinHeap<QueueItem>): void;
|
---|
29 | dequeue(workerId: number): QueueChildMessage | null;
|
---|
30 | _getWorkerQueue(workerId: number): MinHeap<QueueItem>;
|
---|
31 | }
|
---|
32 | declare type HeapItem = {
|
---|
33 | priority: number;
|
---|
34 | };
|
---|
35 | declare class MinHeap<TItem extends HeapItem> {
|
---|
36 | private _heap;
|
---|
37 | peek(): TItem | null;
|
---|
38 | add(item: TItem): void;
|
---|
39 | poll(): TItem | null;
|
---|
40 | }
|
---|
41 | export {};
|
---|
Note:
See
TracBrowser
for help on using the repository browser.