Skip to content

Commit

Permalink
Fix TS build
Browse files Browse the repository at this point in the history
Fixes: 8f8813a ("Add PriorityTaskQueue")
  • Loading branch information
aymanbagabas committed Oct 19, 2022
1 parent a0ab52d commit a10dfa5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/common/TaskQueue.ts
Expand Up @@ -22,18 +22,22 @@ interface ITaskQueue {
clear(): void;
}

// TimeoutId is a type alias for the return type of setTimeout. NodeJS returns
// NodeJS.Timeout, the browser returns number.
type TimeoutId = number | NodeJS.Timeout;

interface ITaskDeadline {
timeRemaining(): number;
}
type CallbackWithDeadline = (deadline: ITaskDeadline) => void;

abstract class TaskQueue implements ITaskQueue {
private _tasks: (() => void)[] = [];
private _idleCallback?: number;
private _idleCallback?: TimeoutId;
private _i = 0;

protected abstract _requestCallback(callback: CallbackWithDeadline): number;
protected abstract _cancelCallback(identifier: number): void;
protected abstract _requestCallback(callback: CallbackWithDeadline): TimeoutId;
protected abstract _cancelCallback(identifier: TimeoutId): void;

public enqueue(task: () => void): void {
this._tasks.push(task);
Expand Down Expand Up @@ -88,7 +92,7 @@ abstract class TaskQueue implements ITaskQueue {
* and care should be taken to ensure they're non-urgent and will not introduce race conditions.
*/
export class PriorityTaskQueue extends TaskQueue {
protected _requestCallback(callback: CallbackWithDeadline): number {
protected _requestCallback(callback: CallbackWithDeadline): TimeoutId {
return setTimeout(() => callback(this._createDeadline(16)));
}

Expand Down

0 comments on commit a10dfa5

Please sign in to comment.