New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@aurelia/scheduler

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aurelia/scheduler - npm Package Compare versions

Comparing version 0.8.0-dev.202010091307 to 0.8.0-dev.202010121021

8

dist/esnext/log.js

@@ -15,4 +15,4 @@ import { TaskQueue } from './task-queue';

const prio = obj['priority'];
const procAsync = !!obj['processingAsync'];
const info = `processing=${processing} pending=${pending} delayed=${delayed} flushReq=${flushReq} prio=${prio} procAsync=${procAsync}`;
const susTask = !!obj['suspenderTask'];
const info = `processing=${processing} pending=${pending} delayed=${delayed} flushReq=${flushReq} prio=${prio} susTask=${susTask}`;
console.log(`${prefix}[Q.${method}] ${info}`);

@@ -27,5 +27,5 @@ }

const persistent = obj['persistent'];
const async = obj['async'];
const suspend = obj['suspend'];
const status = obj['_status'];
const info = `id=${id} created=${created} queue=${queue} preempt=${preempt} persistent=${persistent} reusable=${reusable} status=${status} async=${async}`;
const info = `id=${id} created=${created} queue=${queue} preempt=${preempt} persistent=${persistent} reusable=${reusable} status=${status} suspend=${suspend}`;
console.log(`${prefix}[T.${method}] ${info}`);

@@ -32,0 +32,0 @@ }

@@ -7,3 +7,3 @@ import { DI } from '@aurelia/kernel';

export class Scheduler {
constructor(now, microtaskFactory, renderFactory, macroTaskFactory, postRenderFactory, idleFactory) {
constructor(now, microtaskFactory, renderFactory, macroTaskFactory, postRenderFactory) {
this.taskQueues = [

@@ -14,3 +14,2 @@ this.microtask = (new TaskQueue(now, 0 /* microTask */, this, microtaskFactory)),

this.postRender = (new TaskQueue(now, 3 /* postRender */, this, postRenderFactory)),
this.idle = (new TaskQueue(now, 4 /* idle */, this, idleFactory)),
];

@@ -21,3 +20,2 @@ this.yieldMicroTask = this.yieldMicroTask.bind(this);

this.yieldPostRenderTask = this.yieldPostRenderTask.bind(this);
this.yieldIdleTask = this.yieldIdleTask.bind(this);
this.yieldAll = this.yieldAll.bind(this);

@@ -38,4 +36,4 @@ }

queueTask(callback, opts) {
const { delay, preempt, priority, persistent, reusable, async } = { ...defaultQueueTaskOptions, ...opts };
return this.taskQueues[priority].queueTask(callback, { delay, preempt, persistent, reusable, async });
const { delay, preempt, priority, persistent, reusable, suspend } = { ...defaultQueueTaskOptions, ...opts };
return this.taskQueues[priority].queueTask(callback, { delay, preempt, persistent, reusable, suspend });
}

@@ -54,5 +52,2 @@ getMicroTaskQueue() {

}
getIdleTaskQueue() {
return this.idle;
}
yieldMicroTask() {

@@ -70,5 +65,2 @@ return this.microtask.yield();

}
yieldIdleTask() {
return this.idle.yield();
}
async yieldAll(repeat = 1) {

@@ -80,3 +72,2 @@ while (repeat-- > 0) {

await this.yieldPostRenderTask();
await this.yieldIdleTask();
}

@@ -96,6 +87,3 @@ }

}
queueIdleTask(callback, opts) {
return this.idle.queueTask(callback, opts);
}
}
//# sourceMappingURL=scheduler.js.map

@@ -12,3 +12,4 @@ import { createExposedPromise, defaultQueueTaskOptions, } from './types';

this.processingTail = void 0;
this.processingAsync = void 0;
this.suspenderTask = void 0;
this.pendingAsyncCount = 0;
this.pendingSize = 0;

@@ -41,2 +42,5 @@ this.pendingHead = void 0;

get hasNoMoreFiniteWork() {
if (this.pendingAsyncCount > 0) {
return false;
}
let cur = this.processingHead;

@@ -75,3 +79,3 @@ while (cur !== void 0) {

// Only process normally if we are *not* currently waiting for an async task to finish
if (this.processingAsync === void 0) {
if (this.suspenderTask === void 0) {
if (this.pendingSize > 0) {

@@ -89,6 +93,11 @@ this.movePendingToProcessing();

if (cur.status === 'running') {
this.processingAsync = cur;
this.requestFlushClamped();
leave(this, 'flush early async');
return;
if (cur.suspend === true) {
this.suspenderTask = cur;
this.requestFlushClamped();
leave(this, 'flush early async');
return;
}
else {
++this.pendingAsyncCount;
}
}

@@ -105,3 +114,3 @@ }

}
else if (this.delayedSize > 0) {
else if (this.delayedSize > 0 || this.pendingAsyncCount > 0) {
this.requestFlushClamped();

@@ -119,3 +128,3 @@ }

// Should the task finish before the next flush is invoked,
// the callback to `completeAsyncTask` will have reset `this.processingAsync` back to undefined so processing can return back to normal next flush.
// the callback to `completeAsyncTask` will have reset `this.suspenderTask` back to undefined so processing can return back to normal next flush.
this.requestFlushClamped();

@@ -167,3 +176,3 @@ }

enter(this, 'queueTask');
const { delay, preempt, persistent, reusable, async } = { ...defaultQueueTaskOptions, ...opts };
const { delay, preempt, persistent, reusable, suspend } = { ...defaultQueueTaskOptions, ...opts };
if (preempt) {

@@ -192,10 +201,10 @@ if (delay > 0) {

this.taskPoolSize = index;
task.reuse(time, delay, preempt, persistent, async, callback);
task.reuse(time, delay, preempt, persistent, suspend, callback);
}
else {
task = new Task(this, time, time + delay, preempt, persistent, async, reusable, callback);
task = new Task(this, time, time + delay, preempt, persistent, suspend, reusable, callback);
}
}
else {
task = new Task(this, time, time + delay, preempt, persistent, async, reusable, callback);
task = new Task(this, time, time + delay, preempt, persistent, suspend, reusable, callback);
}

@@ -343,7 +352,12 @@ if (preempt) {

enter(this, 'completeAsyncTask');
if (this.processingAsync !== task) {
leave(this, 'completeAsyncTask error');
throw new Error(`Async task completion mismatch: processingAsync=${(_a = this.processingAsync) === null || _a === void 0 ? void 0 : _a.id}, task=${task.id}`);
if (task.suspend === true) {
if (this.suspenderTask !== task) {
leave(this, 'completeAsyncTask error');
throw new Error(`Async task completion mismatch: suspenderTask=${(_a = this.suspenderTask) === null || _a === void 0 ? void 0 : _a.id}, task=${task.id}`);
}
this.suspenderTask = void 0;
}
this.processingAsync = void 0;
else {
--this.pendingAsyncCount;
}
if (this.yieldPromise !== void 0 &&

@@ -517,4 +531,4 @@ this.hasNoMoreFiniteWork) {

reusable: true,
async: false,
suspend: false,
};
//# sourceMappingURL=task-queue.js.map

@@ -11,3 +11,3 @@ import { createExposedPromise, } from './types';

export class Task {
constructor(taskQueue, createdTime, queueTime, preempt, persistent, async, reusable, callback) {
constructor(taskQueue, createdTime, queueTime, preempt, persistent, suspend, reusable, callback) {
this.taskQueue = taskQueue;

@@ -18,3 +18,3 @@ this.createdTime = createdTime;

this.persistent = persistent;
this.async = async;
this.suspend = suspend;
this.reusable = reusable;

@@ -63,3 +63,3 @@ this.callback = callback;

// so we can set the correct cancelation state.
const { persistent, reusable, taskQueue, callback, resolve, reject, createdTime, async, } = this;
const { persistent, reusable, taskQueue, callback, resolve, reject, createdTime, } = this;
taskQueue.remove(this);

@@ -69,5 +69,4 @@ this._status = 'running';

const ret = callback(taskQueue.now() - createdTime);
if (async === true || (async === 'auto' && ret instanceof Promise)) {
ret
.then($ret => {
if (ret instanceof Promise) {
ret.then($ret => {
if (this.persistent) {

@@ -185,3 +184,3 @@ taskQueue.resetPersistentTask(this);

}
reuse(time, delay, preempt, persistent, async, callback) {
reuse(time, delay, preempt, persistent, suspend, callback) {
enter(this, 'reuse');

@@ -192,3 +191,3 @@ this.createdTime = time;

this.persistent = persistent;
this.async = async;
this.suspend = suspend;
this.callback = callback;

@@ -195,0 +194,0 @@ this._status = 'pending';

@@ -7,3 +7,2 @@ export var TaskQueuePriority;

TaskQueuePriority[TaskQueuePriority["postRender"] = 3] = "postRender";
TaskQueuePriority[TaskQueuePriority["idle"] = 4] = "idle";
})(TaskQueuePriority || (TaskQueuePriority = {}));

@@ -16,3 +15,3 @@ export const defaultQueueTaskOptions = {

reusable: true,
async: false,
suspend: false,
};

@@ -19,0 +18,0 @@ let $resolve;

@@ -14,3 +14,2 @@ import { QueueTaskOptions, QueueTaskTargetOptions, TaskQueuePriority } from './types';

getPostRenderTaskQueue(): ITaskQueue;
getIdleTaskQueue(): ITaskQueue;
yieldMicroTask(): Promise<void>;

@@ -20,3 +19,2 @@ yieldRenderTask(): Promise<void>;

yieldPostRenderTask(): Promise<void>;
yieldIdleTask(): Promise<void>;
yieldAll(repeat?: number): Promise<void>;

@@ -27,3 +25,2 @@ queueMicroTask<T = any>(callback: TaskCallback<T>, opts?: QueueTaskOptions): ITask<T>;

queuePostRenderTask<T = any>(callback: TaskCallback<T>, opts?: QueueTaskOptions): ITask<T>;
queueIdleTask<T = any>(callback: TaskCallback<T>, opts?: QueueTaskOptions): ITask<T>;
}

@@ -36,4 +33,3 @@ export declare class Scheduler implements IScheduler {

private readonly postRender;
private readonly idle;
constructor(now: Now, microtaskFactory: IFlushRequestorFactory, renderFactory: IFlushRequestorFactory, macroTaskFactory: IFlushRequestorFactory, postRenderFactory: IFlushRequestorFactory, idleFactory: IFlushRequestorFactory);
constructor(now: Now, microtaskFactory: IFlushRequestorFactory, renderFactory: IFlushRequestorFactory, macroTaskFactory: IFlushRequestorFactory, postRenderFactory: IFlushRequestorFactory);
static get(key: object): IScheduler | undefined;

@@ -48,3 +44,2 @@ static set(key: object, instance: IScheduler): void;

getPostRenderTaskQueue(): ITaskQueue;
getIdleTaskQueue(): ITaskQueue;
yieldMicroTask(): Promise<void>;

@@ -54,3 +49,2 @@ yieldRenderTask(): Promise<void>;

yieldPostRenderTask(): Promise<void>;
yieldIdleTask(): Promise<void>;
yieldAll(repeat?: number): Promise<void>;

@@ -61,4 +55,3 @@ queueMicroTask<T = any>(callback: TaskCallback<T>, opts?: QueueTaskOptions): ITask<T>;

queuePostRenderTask<T = any>(callback: TaskCallback<T>, opts?: QueueTaskOptions): ITask<T>;
queueIdleTask<T = any>(callback: TaskCallback<T>, opts?: QueueTaskOptions): ITask<T>;
}
//# sourceMappingURL=scheduler.d.ts.map

@@ -29,3 +29,4 @@ import { QueueTaskOptions, TaskQueuePriority } from './types';

private processingTail;
private processingAsync;
private suspenderTask;
private pendingAsyncCount;
private pendingSize;

@@ -32,0 +33,0 @@ private pendingHead;

@@ -22,3 +22,3 @@ import { TaskQueuePriority } from './types';

persistent: boolean;
async: boolean | 'auto';
suspend: boolean;
readonly reusable: boolean;

@@ -36,9 +36,9 @@ callback: TaskCallback<T>;

readonly priority: TaskQueuePriority;
constructor(taskQueue: TaskQueue, createdTime: number, queueTime: number, preempt: boolean, persistent: boolean, async: boolean | 'auto', reusable: boolean, callback: TaskCallback<T>);
constructor(taskQueue: TaskQueue, createdTime: number, queueTime: number, preempt: boolean, persistent: boolean, suspend: boolean, reusable: boolean, callback: TaskCallback<T>);
run(): void;
cancel(): boolean;
reset(time: number): void;
reuse(time: number, delay: number, preempt: boolean, persistent: boolean, async: boolean | 'auto', callback: TaskCallback<T>): void;
reuse(time: number, delay: number, preempt: boolean, persistent: boolean, suspend: boolean, callback: TaskCallback<T>): void;
dispose(): void;
}
//# sourceMappingURL=task.d.ts.map

@@ -5,4 +5,3 @@ export declare const enum TaskQueuePriority {

macroTask = 2,
postRender = 3,
idle = 4
postRender = 3
}

@@ -39,9 +38,7 @@ export declare type QueueTaskOptions = {

/**
* If `true`, the return value of the callback will be treated as a promise. Consecutive tasks will be run only after the promise resolved.
* If `true`, and the task callback returns a promise, that promise will be awaited before consecutive tasks are run.
*
* If `'auto'`, the return value of the callback will be treated as a promise only if is an instance of a promise. Use this only for callbacks that can either return `void` or `Promise` and it can't be determined upfront which of the two it is. For dealing with promises, this is less efficient than passing in `true`.
*
* Defaults to `false`
* Defaults to `false`.
*/
async?: boolean | 'auto';
suspend?: boolean;
};

@@ -48,0 +45,0 @@ export declare type QueueTaskTargetOptions = QueueTaskOptions & {

@@ -28,4 +28,4 @@ (function (factory) {

const prio = obj['priority'];
const procAsync = !!obj['processingAsync'];
const info = `processing=${processing} pending=${pending} delayed=${delayed} flushReq=${flushReq} prio=${prio} procAsync=${procAsync}`;
const susTask = !!obj['suspenderTask'];
const info = `processing=${processing} pending=${pending} delayed=${delayed} flushReq=${flushReq} prio=${prio} susTask=${susTask}`;
console.log(`${prefix}[Q.${method}] ${info}`);

@@ -40,5 +40,5 @@ }

const persistent = obj['persistent'];
const async = obj['async'];
const suspend = obj['suspend'];
const status = obj['_status'];
const info = `id=${id} created=${created} queue=${queue} preempt=${preempt} persistent=${persistent} reusable=${reusable} status=${status} async=${async}`;
const info = `id=${id} created=${created} queue=${queue} preempt=${preempt} persistent=${persistent} reusable=${reusable} status=${status} suspend=${suspend}`;
console.log(`${prefix}[T.${method}] ${info}`);

@@ -45,0 +45,0 @@ }

@@ -19,3 +19,3 @@ (function (factory) {

class Scheduler {
constructor(now, microtaskFactory, renderFactory, macroTaskFactory, postRenderFactory, idleFactory) {
constructor(now, microtaskFactory, renderFactory, macroTaskFactory, postRenderFactory) {
this.taskQueues = [

@@ -26,3 +26,2 @@ this.microtask = (new task_queue_1.TaskQueue(now, 0 /* microTask */, this, microtaskFactory)),

this.postRender = (new task_queue_1.TaskQueue(now, 3 /* postRender */, this, postRenderFactory)),
this.idle = (new task_queue_1.TaskQueue(now, 4 /* idle */, this, idleFactory)),
];

@@ -33,3 +32,2 @@ this.yieldMicroTask = this.yieldMicroTask.bind(this);

this.yieldPostRenderTask = this.yieldPostRenderTask.bind(this);
this.yieldIdleTask = this.yieldIdleTask.bind(this);
this.yieldAll = this.yieldAll.bind(this);

@@ -50,4 +48,4 @@ }

queueTask(callback, opts) {
const { delay, preempt, priority, persistent, reusable, async } = { ...types_1.defaultQueueTaskOptions, ...opts };
return this.taskQueues[priority].queueTask(callback, { delay, preempt, persistent, reusable, async });
const { delay, preempt, priority, persistent, reusable, suspend } = { ...types_1.defaultQueueTaskOptions, ...opts };
return this.taskQueues[priority].queueTask(callback, { delay, preempt, persistent, reusable, suspend });
}

@@ -66,5 +64,2 @@ getMicroTaskQueue() {

}
getIdleTaskQueue() {
return this.idle;
}
yieldMicroTask() {

@@ -82,5 +77,2 @@ return this.microtask.yield();

}
yieldIdleTask() {
return this.idle.yield();
}
async yieldAll(repeat = 1) {

@@ -92,3 +84,2 @@ while (repeat-- > 0) {

await this.yieldPostRenderTask();
await this.yieldIdleTask();
}

@@ -108,5 +99,2 @@ }

}
queueIdleTask(callback, opts) {
return this.idle.queueTask(callback, opts);
}
}

@@ -113,0 +101,0 @@ exports.Scheduler = Scheduler;

@@ -24,3 +24,4 @@ (function (factory) {

this.processingTail = void 0;
this.processingAsync = void 0;
this.suspenderTask = void 0;
this.pendingAsyncCount = 0;
this.pendingSize = 0;

@@ -53,2 +54,5 @@ this.pendingHead = void 0;

get hasNoMoreFiniteWork() {
if (this.pendingAsyncCount > 0) {
return false;
}
let cur = this.processingHead;

@@ -87,3 +91,3 @@ while (cur !== void 0) {

// Only process normally if we are *not* currently waiting for an async task to finish
if (this.processingAsync === void 0) {
if (this.suspenderTask === void 0) {
if (this.pendingSize > 0) {

@@ -101,6 +105,11 @@ this.movePendingToProcessing();

if (cur.status === 'running') {
this.processingAsync = cur;
this.requestFlushClamped();
log_1.leave(this, 'flush early async');
return;
if (cur.suspend === true) {
this.suspenderTask = cur;
this.requestFlushClamped();
log_1.leave(this, 'flush early async');
return;
}
else {
++this.pendingAsyncCount;
}
}

@@ -117,3 +126,3 @@ }

}
else if (this.delayedSize > 0) {
else if (this.delayedSize > 0 || this.pendingAsyncCount > 0) {
this.requestFlushClamped();

@@ -131,3 +140,3 @@ }

// Should the task finish before the next flush is invoked,
// the callback to `completeAsyncTask` will have reset `this.processingAsync` back to undefined so processing can return back to normal next flush.
// the callback to `completeAsyncTask` will have reset `this.suspenderTask` back to undefined so processing can return back to normal next flush.
this.requestFlushClamped();

@@ -179,3 +188,3 @@ }

log_1.enter(this, 'queueTask');
const { delay, preempt, persistent, reusable, async } = { ...types_1.defaultQueueTaskOptions, ...opts };
const { delay, preempt, persistent, reusable, suspend } = { ...types_1.defaultQueueTaskOptions, ...opts };
if (preempt) {

@@ -204,10 +213,10 @@ if (delay > 0) {

this.taskPoolSize = index;
task.reuse(time, delay, preempt, persistent, async, callback);
task.reuse(time, delay, preempt, persistent, suspend, callback);
}
else {
task = new task_1.Task(this, time, time + delay, preempt, persistent, async, reusable, callback);
task = new task_1.Task(this, time, time + delay, preempt, persistent, suspend, reusable, callback);
}
}
else {
task = new task_1.Task(this, time, time + delay, preempt, persistent, async, reusable, callback);
task = new task_1.Task(this, time, time + delay, preempt, persistent, suspend, reusable, callback);
}

@@ -355,7 +364,12 @@ if (preempt) {

log_1.enter(this, 'completeAsyncTask');
if (this.processingAsync !== task) {
log_1.leave(this, 'completeAsyncTask error');
throw new Error(`Async task completion mismatch: processingAsync=${(_a = this.processingAsync) === null || _a === void 0 ? void 0 : _a.id}, task=${task.id}`);
if (task.suspend === true) {
if (this.suspenderTask !== task) {
log_1.leave(this, 'completeAsyncTask error');
throw new Error(`Async task completion mismatch: suspenderTask=${(_a = this.suspenderTask) === null || _a === void 0 ? void 0 : _a.id}, task=${task.id}`);
}
this.suspenderTask = void 0;
}
this.processingAsync = void 0;
else {
--this.pendingAsyncCount;
}
if (this.yieldPromise !== void 0 &&

@@ -530,5 +544,5 @@ this.hasNoMoreFiniteWork) {

reusable: true,
async: false,
suspend: false,
};
});
//# sourceMappingURL=task-queue.js.map

@@ -24,3 +24,3 @@ (function (factory) {

class Task {
constructor(taskQueue, createdTime, queueTime, preempt, persistent, async, reusable, callback) {
constructor(taskQueue, createdTime, queueTime, preempt, persistent, suspend, reusable, callback) {
this.taskQueue = taskQueue;

@@ -31,3 +31,3 @@ this.createdTime = createdTime;

this.persistent = persistent;
this.async = async;
this.suspend = suspend;
this.reusable = reusable;

@@ -76,3 +76,3 @@ this.callback = callback;

// so we can set the correct cancelation state.
const { persistent, reusable, taskQueue, callback, resolve, reject, createdTime, async, } = this;
const { persistent, reusable, taskQueue, callback, resolve, reject, createdTime, } = this;
taskQueue.remove(this);

@@ -82,5 +82,4 @@ this._status = 'running';

const ret = callback(taskQueue.now() - createdTime);
if (async === true || (async === 'auto' && ret instanceof Promise)) {
ret
.then($ret => {
if (ret instanceof Promise) {
ret.then($ret => {
if (this.persistent) {

@@ -198,3 +197,3 @@ taskQueue.resetPersistentTask(this);

}
reuse(time, delay, preempt, persistent, async, callback) {
reuse(time, delay, preempt, persistent, suspend, callback) {
log_1.enter(this, 'reuse');

@@ -205,3 +204,3 @@ this.createdTime = time;

this.persistent = persistent;
this.async = async;
this.suspend = suspend;
this.callback = callback;

@@ -208,0 +207,0 @@ this._status = 'pending';

@@ -19,3 +19,2 @@ (function (factory) {

TaskQueuePriority[TaskQueuePriority["postRender"] = 3] = "postRender";
TaskQueuePriority[TaskQueuePriority["idle"] = 4] = "idle";
})(TaskQueuePriority = exports.TaskQueuePriority || (exports.TaskQueuePriority = {}));

@@ -28,3 +27,3 @@ exports.defaultQueueTaskOptions = {

reusable: true,
async: false,
suspend: false,
};

@@ -31,0 +30,0 @@ let $resolve;

{
"name": "@aurelia/scheduler",
"version": "0.8.0-dev.202010091307",
"version": "0.8.0-dev.202010121021",
"main": "dist/umd/index.js",

@@ -37,4 +37,4 @@ "module": "dist/esnext/index.js",

"dependencies": {
"@aurelia/kernel": "^0.8.0-dev.202010091307",
"@aurelia/metadata": "^0.8.0-dev.202010091307"
"@aurelia/kernel": "^0.8.0-dev.202010121021",
"@aurelia/metadata": "^0.8.0-dev.202010121021"
},

@@ -44,3 +44,3 @@ "devDependencies": {

},
"gitHead": "74ff11175ce91ee68fa1fe65172601793983d293"
"gitHead": "2ca777f76e6fe2a2f11428ab778b44e2c18c7a90"
}

@@ -28,5 +28,5 @@ import { TaskQueue } from './task-queue';

const prio = obj['priority'];
const procAsync = !!obj['processingAsync'];
const susTask = !!obj['suspenderTask'];
const info = `processing=${processing} pending=${pending} delayed=${delayed} flushReq=${flushReq} prio=${prio} procAsync=${procAsync}`;
const info = `processing=${processing} pending=${pending} delayed=${delayed} flushReq=${flushReq} prio=${prio} susTask=${susTask}`;
console.log(`${prefix}[Q.${method}] ${info}`);

@@ -40,6 +40,6 @@ } else {

const persistent = obj['persistent'];
const async = obj['async'];
const suspend = obj['suspend'];
const status = obj['_status'];
const info = `id=${id} created=${created} queue=${queue} preempt=${preempt} persistent=${persistent} reusable=${reusable} status=${status} async=${async}`;
const info = `id=${id} created=${created} queue=${queue} preempt=${preempt} persistent=${persistent} reusable=${reusable} status=${status} suspend=${suspend}`;
console.log(`${prefix}[T.${method}] ${info}`);

@@ -46,0 +46,0 @@ }

@@ -35,3 +35,2 @@ import { DI } from '@aurelia/kernel';

getPostRenderTaskQueue(): ITaskQueue;
getIdleTaskQueue(): ITaskQueue;

@@ -42,3 +41,2 @@ yieldMicroTask(): Promise<void>;

yieldPostRenderTask(): Promise<void>;
yieldIdleTask(): Promise<void>;
yieldAll(repeat?: number): Promise<void>;

@@ -50,3 +48,2 @@

queuePostRenderTask<T = any>(callback: TaskCallback<T>, opts?: QueueTaskOptions): ITask<T>;
queueIdleTask<T = any>(callback: TaskCallback<T>, opts?: QueueTaskOptions): ITask<T>;
}

@@ -60,3 +57,2 @@

TaskQueue,
TaskQueue,
];

@@ -67,3 +63,2 @@ private readonly microtask: TaskQueue;

private readonly postRender: TaskQueue;
private readonly idle: TaskQueue;

@@ -76,3 +71,2 @@ public constructor(

postRenderFactory: IFlushRequestorFactory,
idleFactory: IFlushRequestorFactory,
) {

@@ -92,5 +86,2 @@ this.taskQueues = [

),
this.idle = (
new TaskQueue(now, TaskQueuePriority.idle, this, idleFactory)
),
];

@@ -102,3 +93,2 @@

this.yieldPostRenderTask = this.yieldPostRenderTask.bind(this);
this.yieldIdleTask = this.yieldIdleTask.bind(this);
this.yieldAll = this.yieldAll.bind(this);

@@ -124,4 +114,4 @@ }

public queueTask<T = any>(callback: TaskCallback<T>, opts?: QueueTaskTargetOptions): Task<T> {
const { delay, preempt, priority, persistent, reusable, async } = { ...defaultQueueTaskOptions, ...opts };
return this.taskQueues[priority].queueTask(callback, { delay, preempt, persistent, reusable, async });
const { delay, preempt, priority, persistent, reusable, suspend } = { ...defaultQueueTaskOptions, ...opts };
return this.taskQueues[priority].queueTask(callback, { delay, preempt, persistent, reusable, suspend });
}

@@ -141,5 +131,2 @@

}
public getIdleTaskQueue(): ITaskQueue {
return this.idle;
}

@@ -158,5 +145,2 @@ public yieldMicroTask(): Promise<void> {

}
public yieldIdleTask(): Promise<void> {
return this.idle.yield();
}
public async yieldAll(repeat: number = 1): Promise<void> {

@@ -168,3 +152,2 @@ while (repeat-- > 0) {

await this.yieldPostRenderTask();
await this.yieldIdleTask();
}

@@ -185,6 +168,3 @@ }

}
public queueIdleTask<T = any>(callback: TaskCallback<T>, opts?: QueueTaskOptions): ITask<T> {
return this.idle.queueTask(callback, opts);
}
}

@@ -50,3 +50,4 @@ import {

private processingAsync: Task | undefined = void 0;
private suspenderTask: Task | undefined = void 0;
private pendingAsyncCount: number = 0;

@@ -83,2 +84,5 @@ private pendingSize: number = 0;

private get hasNoMoreFiniteWork(): boolean {
if (this.pendingAsyncCount > 0) {
return false;
}
let cur = this.processingHead;

@@ -134,3 +138,3 @@ while (cur !== void 0) {

// Only process normally if we are *not* currently waiting for an async task to finish
if (this.processingAsync === void 0) {
if (this.suspenderTask === void 0) {
if (this.pendingSize > 0) {

@@ -149,8 +153,12 @@ this.movePendingToProcessing();

if (cur.status === 'running') {
this.processingAsync = cur;
this.requestFlushClamped();
if (cur.suspend === true) {
this.suspenderTask = cur;
this.requestFlushClamped();
leave(this, 'flush early async');
leave(this, 'flush early async');
return;
return;
} else {
++this.pendingAsyncCount;
}
}

@@ -168,3 +176,3 @@ }

this.requestFlush();
} else if (this.delayedSize > 0) {
} else if (this.delayedSize > 0 || this.pendingAsyncCount > 0) {
this.requestFlushClamped();

@@ -184,3 +192,3 @@ }

// Should the task finish before the next flush is invoked,
// the callback to `completeAsyncTask` will have reset `this.processingAsync` back to undefined so processing can return back to normal next flush.
// the callback to `completeAsyncTask` will have reset `this.suspenderTask` back to undefined so processing can return back to normal next flush.
this.requestFlushClamped();

@@ -242,3 +250,3 @@ }

const { delay, preempt, persistent, reusable, async } = { ...defaultQueueTaskOptions, ...opts };
const { delay, preempt, persistent, reusable, suspend } = { ...defaultQueueTaskOptions, ...opts };

@@ -272,8 +280,8 @@ if (preempt) {

task.reuse(time, delay, preempt, persistent, async, callback);
task.reuse(time, delay, preempt, persistent, suspend, callback);
} else {
task = new Task(this, time, time + delay, preempt, persistent, async, reusable, callback);
task = new Task(this, time, time + delay, preempt, persistent, suspend, reusable, callback);
}
} else {
task = new Task(this, time, time + delay, preempt, persistent, async, reusable, callback);
task = new Task(this, time, time + delay, preempt, persistent, suspend, reusable, callback);
}

@@ -446,9 +454,14 @@

if (this.processingAsync !== task) {
leave(this, 'completeAsyncTask error');
if (task.suspend === true) {
if (this.suspenderTask !== task) {
leave(this, 'completeAsyncTask error');
throw new Error(`Async task completion mismatch: processingAsync=${this.processingAsync?.id}, task=${task.id}`);
throw new Error(`Async task completion mismatch: suspenderTask=${this.suspenderTask?.id}, task=${task.id}`);
}
this.suspenderTask = void 0;
} else {
--this.pendingAsyncCount;
}
this.processingAsync = void 0;
if (

@@ -665,3 +678,3 @@ this.yieldPromise !== void 0 &&

reusable: true,
async: false,
suspend: false,
};

@@ -76,3 +76,3 @@ import {

public persistent: boolean,
public async: boolean | 'auto',
public suspend: boolean,
public readonly reusable: boolean,

@@ -104,3 +104,2 @@ public callback: TaskCallback<T>,

createdTime,
async,
} = this;

@@ -114,5 +113,4 @@

const ret = callback(taskQueue.now() - createdTime);
if (async === true || (async === 'auto' && ret instanceof Promise)) {
(ret as unknown as Promise<T>)
.then($ret => {
if (ret instanceof Promise) {
ret.then($ret => {
if (this.persistent) {

@@ -260,3 +258,3 @@ taskQueue.resetPersistentTask(this);

persistent: boolean,
async: boolean | 'auto',
suspend: boolean,
callback: TaskCallback<T>,

@@ -270,3 +268,3 @@ ): void {

this.persistent = persistent;
this.async = async;
this.suspend = suspend;
this.callback = callback;

@@ -273,0 +271,0 @@ this._status = 'pending';

@@ -6,3 +6,2 @@ export const enum TaskQueuePriority {

postRender = 3,
idle = 4,
}

@@ -40,9 +39,7 @@

/**
* If `true`, the return value of the callback will be treated as a promise. Consecutive tasks will be run only after the promise resolved.
* If `true`, and the task callback returns a promise, that promise will be awaited before consecutive tasks are run.
*
* If `'auto'`, the return value of the callback will be treated as a promise only if is an instance of a promise. Use this only for callbacks that can either return `void` or `Promise` and it can't be determined upfront which of the two it is. For dealing with promises, this is less efficient than passing in `true`.
*
* Defaults to `false`
* Defaults to `false`.
*/
async?: boolean | 'auto';
suspend?: boolean;
};

@@ -60,3 +57,3 @@

reusable: true,
async: false,
suspend: false,
};

@@ -63,0 +60,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc