Docs
This commit is contained in:
@@ -3,16 +3,27 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A queue of that runs tasks over several idle callbacks, trying to maintain the specified
|
||||||
|
* frame rate. The tasks will run in the order they are enqueued, but they will run some time later,
|
||||||
|
* and care should be taken to ensure they're non-urgent and will not introduce race conditions.
|
||||||
|
*/
|
||||||
export class IdleTaskQueue {
|
export class IdleTaskQueue {
|
||||||
private _tasks: Function[] = [];
|
private _tasks: Function[] = [];
|
||||||
private _idleCallback?: number;
|
private _idleCallback?: number;
|
||||||
private _maxTaskDuration: number;
|
private _maxTaskDuration: number;
|
||||||
private _i = 0;
|
private _i = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param targetFps The target frame rate.
|
||||||
|
*/
|
||||||
constructor(targetFps: number = 240) {
|
constructor(targetFps: number = 240) {
|
||||||
this._maxTaskDuration = 1000 / targetFps;
|
this._maxTaskDuration = 1000 / targetFps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a task to the queue which will run in a future idle callback.
|
||||||
|
*/
|
||||||
public enqueue(task: Function): void {
|
public enqueue(task: Function): void {
|
||||||
this._tasks.push(task);
|
this._tasks.push(task);
|
||||||
this._start();
|
this._start();
|
||||||
|
|||||||
Reference in New Issue
Block a user