@reactive-js/schedulers
Advanced tools
Comparing version 0.0.19 to 0.0.20
export { createPrioritySchedulerResource, PrioritySchedulerLike, PrioritySchedulerResourceLike, } from "./internal/priorityScheduler"; | ||
export { createVirtualTimeSchedulerResource, VirtualTimeSchedulerResourceLike, } from "./internal/virtualTimeScheduler"; | ||
export { createSynchronousSchedulerResource } from "./internal/synchronousScheduler"; | ||
export { createSchedulerWithPriority } from "./internal/schedulerWithPriority"; | ||
export { AbstractScheduler, AbstractSchedulerResource, } from "./internal/abstractScheduler"; |
@@ -7,4 +7,2 @@ "use strict"; | ||
exports.createVirtualTimeSchedulerResource = virtualTimeScheduler_1.createVirtualTimeSchedulerResource; | ||
var synchronousScheduler_1 = require("./internal/synchronousScheduler"); | ||
exports.createSynchronousSchedulerResource = synchronousScheduler_1.createSynchronousSchedulerResource; | ||
var schedulerWithPriority_1 = require("./internal/schedulerWithPriority"); | ||
@@ -11,0 +9,0 @@ exports.createSchedulerWithPriority = schedulerWithPriority_1.createSchedulerWithPriority; |
import { DisposableLike, DisposableOrTeardown } from "@reactive-js/disposable"; | ||
import { SchedulerLike, SchedulerContinuationLike, SchedulerResourceLike } from "@reactive-js/scheduler"; | ||
export declare abstract class AbstractScheduler implements SchedulerLike { | ||
private currentDisposable; | ||
private startTime; | ||
private shouldYield; | ||
protected abstract shouldCallbackYield(startTime: number): boolean; | ||
protected abstract get shouldYield(): (() => boolean) | undefined; | ||
protected abstract scheduleCallback(callback: () => void, delay?: number): DisposableLike; | ||
@@ -9,0 +6,0 @@ abstract readonly now: number; |
@@ -5,15 +5,6 @@ "use strict"; | ||
class AbstractScheduler { | ||
constructor() { | ||
this.currentDisposable = disposable_1.disposed; | ||
this.startTime = 0; | ||
this.shouldYield = () => this.currentDisposable.isDisposed || | ||
this.shouldCallbackYield(this.startTime); | ||
} | ||
createCallback(continuation, disposable) { | ||
const callback = () => { | ||
if (!disposable.isDisposed) { | ||
this.startTime = this.now; | ||
this.currentDisposable = disposable; | ||
const result = continuation.run(this.shouldYield) || undefined; | ||
this.currentDisposable = disposable_1.disposed; | ||
if (result !== undefined) { | ||
@@ -20,0 +11,0 @@ const { continuation: nextContinuation, delay = 0 } = result; |
@@ -82,8 +82,11 @@ "use strict"; | ||
const nextTask = this.queue.peek(); | ||
if (nextTask !== undefined && shouldYield()) { | ||
if (nextTask !== undefined) { | ||
const now = this.now; | ||
return { | ||
continuation: this, | ||
delay: Math.max(nextTask.dueTime - now, 0), | ||
}; | ||
const nextTaskDelay = Math.max(nextTask.dueTime - now, 0); | ||
if (nextTaskDelay > 0 || (shouldYield !== undefined && shouldYield())) { | ||
return { | ||
continuation: this, | ||
delay: nextTaskDelay, | ||
}; | ||
} | ||
} | ||
@@ -90,0 +93,0 @@ } |
@@ -1,13 +0,4 @@ | ||
import { SchedulerResourceLike } from "@reactive-js/scheduler"; | ||
import { AbstractSchedulerResource } from "./abstractScheduler"; | ||
export interface VirtualTimeSchedulerResourceLike extends SchedulerResourceLike, Iterator<void> { | ||
run(): void; | ||
import { SchedulerResourceLike, SchedulerContinuationLike } from "@reactive-js/scheduler"; | ||
export interface VirtualTimeSchedulerResourceLike extends SchedulerResourceLike, Iterator<void>, SchedulerContinuationLike { | ||
} | ||
export declare abstract class AbstractVirtualTimeSchedulerResource extends AbstractSchedulerResource { | ||
protected abstract step(): boolean; | ||
next(): IteratorResult<void>; | ||
return(): IteratorResult<void>; | ||
throw(e?: any): IteratorResult<void>; | ||
run(): void; | ||
} | ||
export declare const createVirtualTimeSchedulerResource: (maxMicroTaskTicks?: number) => VirtualTimeSchedulerResourceLike; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const disposable_1 = require("@reactive-js/disposable"); | ||
const abstractScheduler_1 = require("./abstractScheduler"); | ||
const priorityQueue_1 = require("./priorityQueue"); | ||
const abstractScheduler_1 = require("./abstractScheduler"); | ||
const iteratorYield = { | ||
@@ -14,26 +14,2 @@ done: false, | ||
}; | ||
class AbstractVirtualTimeSchedulerResource extends abstractScheduler_1.AbstractSchedulerResource { | ||
next() { | ||
disposable_1.throwIfDisposed(this); | ||
const hasMore = this.step(); | ||
return hasMore ? iteratorYield : iteratorDone; | ||
} | ||
return() { | ||
this.dispose(); | ||
return iteratorDone; | ||
} | ||
throw(e) { | ||
this.dispose; | ||
if (e !== undefined) { | ||
throw e; | ||
} | ||
return iteratorDone; | ||
} | ||
run() { | ||
disposable_1.throwIfDisposed(this); | ||
while (this.step()) { } | ||
this.dispose(); | ||
} | ||
} | ||
exports.AbstractVirtualTimeSchedulerResource = AbstractVirtualTimeSchedulerResource; | ||
const comparator = (a, b) => { | ||
@@ -45,15 +21,62 @@ let diff = 0; | ||
}; | ||
class VirtualTimeSchedulerResourceImpl extends AbstractVirtualTimeSchedulerResource { | ||
class VirtualTimeSchedulerResourceImpl extends abstractScheduler_1.AbstractSchedulerResource { | ||
constructor(maxMicroTaskTicks) { | ||
super(); | ||
this.maxMicroTaskTicks = maxMicroTaskTicks; | ||
this.continuationResult = { continuation: this }; | ||
this.microTaskTicks = 0; | ||
this.now = 0; | ||
this.microTaskTicks = 0; | ||
this.taskIDCount = 0; | ||
this.taskQueue = priorityQueue_1.createPriorityQueue(comparator); | ||
this.shouldYield = () => { | ||
const runShouldYield = this.runShouldYield; | ||
this.microTaskTicks++; | ||
return (this.microTaskTicks >= this.maxMicroTaskTicks || | ||
(runShouldYield !== undefined && runShouldYield())); | ||
}; | ||
} | ||
shouldCallbackYield(_) { | ||
this.microTaskTicks++; | ||
return this.microTaskTicks >= this.maxMicroTaskTicks; | ||
loop(shouldYield) { | ||
this.runShouldYield = shouldYield; | ||
while (this.step()) { | ||
if (shouldYield()) { | ||
this.runShouldYield = undefined; | ||
return this.continuationResult; | ||
} | ||
} | ||
this.runShouldYield = undefined; | ||
return; | ||
} | ||
loopFast() { | ||
while (this.step()) { } | ||
} | ||
next() { | ||
disposable_1.throwIfDisposed(this); | ||
const hasMore = this.step(); | ||
return hasMore ? iteratorYield : iteratorDone; | ||
} | ||
return() { | ||
this.dispose(); | ||
return iteratorDone; | ||
} | ||
run(shouldYield) { | ||
disposable_1.throwIfDisposed(this); | ||
if (this.maxMicroTaskTicks === Number.MAX_SAFE_INTEGER && | ||
shouldYield === undefined) { | ||
this.shouldYield = undefined; | ||
} | ||
let result; | ||
if (shouldYield !== undefined) { | ||
result = this.loop(shouldYield); | ||
} | ||
else { | ||
result = this.loopFast(); | ||
} | ||
if (result !== undefined) { | ||
return result; | ||
} | ||
else { | ||
this.dispose(); | ||
return; | ||
} | ||
} | ||
scheduleCallback(callback, delay = 0) { | ||
@@ -84,4 +107,11 @@ const disposable = disposable_1.createDisposable(); | ||
} | ||
throw(e) { | ||
this.dispose; | ||
if (e !== undefined) { | ||
throw e; | ||
} | ||
return iteratorDone; | ||
} | ||
} | ||
exports.createVirtualTimeSchedulerResource = (maxMicroTaskTicks = Number.MAX_SAFE_INTEGER) => new VirtualTimeSchedulerResourceImpl(maxMicroTaskTicks); | ||
//# sourceMappingURL=virtualTimeScheduler.js.map |
export { createPrioritySchedulerResource, PrioritySchedulerLike, PrioritySchedulerResourceLike, } from "./internal/priorityScheduler"; | ||
export { createVirtualTimeSchedulerResource, VirtualTimeSchedulerResourceLike, } from "./internal/virtualTimeScheduler"; | ||
export { createSynchronousSchedulerResource } from "./internal/synchronousScheduler"; | ||
export { createSchedulerWithPriority } from "./internal/schedulerWithPriority"; | ||
export { AbstractScheduler, AbstractSchedulerResource, } from "./internal/abstractScheduler"; |
export { createPrioritySchedulerResource, } from "./internal/priorityScheduler"; | ||
export { createVirtualTimeSchedulerResource, } from "./internal/virtualTimeScheduler"; | ||
export { createSynchronousSchedulerResource } from "./internal/synchronousScheduler"; | ||
export { createSchedulerWithPriority } from "./internal/schedulerWithPriority"; | ||
export { AbstractScheduler, AbstractSchedulerResource, } from "./internal/abstractScheduler"; | ||
//# sourceMappingURL=index.js.map |
import { DisposableLike, DisposableOrTeardown } from "@reactive-js/disposable"; | ||
import { SchedulerLike, SchedulerContinuationLike, SchedulerResourceLike } from "@reactive-js/scheduler"; | ||
export declare abstract class AbstractScheduler implements SchedulerLike { | ||
private currentDisposable; | ||
private startTime; | ||
private shouldYield; | ||
protected abstract shouldCallbackYield(startTime: number): boolean; | ||
protected abstract get shouldYield(): (() => boolean) | undefined; | ||
protected abstract scheduleCallback(callback: () => void, delay?: number): DisposableLike; | ||
@@ -9,0 +6,0 @@ abstract readonly now: number; |
@@ -1,16 +0,7 @@ | ||
import { createDisposable, createSerialDisposable, disposed, } from "@reactive-js/disposable"; | ||
import { createDisposable, createSerialDisposable, } from "@reactive-js/disposable"; | ||
export class AbstractScheduler { | ||
constructor() { | ||
this.currentDisposable = disposed; | ||
this.startTime = 0; | ||
this.shouldYield = () => this.currentDisposable.isDisposed || | ||
this.shouldCallbackYield(this.startTime); | ||
} | ||
createCallback(continuation, disposable) { | ||
const callback = () => { | ||
if (!disposable.isDisposed) { | ||
this.startTime = this.now; | ||
this.currentDisposable = disposable; | ||
const result = continuation.run(this.shouldYield) || undefined; | ||
this.currentDisposable = disposed; | ||
if (result !== undefined) { | ||
@@ -17,0 +8,0 @@ const { continuation: nextContinuation, delay = 0 } = result; |
@@ -80,8 +80,11 @@ import { createDisposable, createSerialDisposable, } from "@reactive-js/disposable"; | ||
const nextTask = this.queue.peek(); | ||
if (nextTask !== undefined && shouldYield()) { | ||
if (nextTask !== undefined) { | ||
const now = this.now; | ||
return { | ||
continuation: this, | ||
delay: Math.max(nextTask.dueTime - now, 0), | ||
}; | ||
const nextTaskDelay = Math.max(nextTask.dueTime - now, 0); | ||
if (nextTaskDelay > 0 || (shouldYield !== undefined && shouldYield())) { | ||
return { | ||
continuation: this, | ||
delay: nextTaskDelay, | ||
}; | ||
} | ||
} | ||
@@ -88,0 +91,0 @@ } |
@@ -1,13 +0,4 @@ | ||
import { SchedulerResourceLike } from "@reactive-js/scheduler"; | ||
import { AbstractSchedulerResource } from "./abstractScheduler"; | ||
export interface VirtualTimeSchedulerResourceLike extends SchedulerResourceLike, Iterator<void> { | ||
run(): void; | ||
import { SchedulerResourceLike, SchedulerContinuationLike } from "@reactive-js/scheduler"; | ||
export interface VirtualTimeSchedulerResourceLike extends SchedulerResourceLike, Iterator<void>, SchedulerContinuationLike { | ||
} | ||
export declare abstract class AbstractVirtualTimeSchedulerResource extends AbstractSchedulerResource { | ||
protected abstract step(): boolean; | ||
next(): IteratorResult<void>; | ||
return(): IteratorResult<void>; | ||
throw(e?: any): IteratorResult<void>; | ||
run(): void; | ||
} | ||
export declare const createVirtualTimeSchedulerResource: (maxMicroTaskTicks?: number) => VirtualTimeSchedulerResourceLike; |
import { createDisposable, throwIfDisposed, } from "@reactive-js/disposable"; | ||
import { AbstractSchedulerResource } from "./abstractScheduler"; | ||
import { createPriorityQueue } from "./priorityQueue"; | ||
import { AbstractSchedulerResource } from "./abstractScheduler"; | ||
const iteratorYield = { | ||
@@ -12,25 +12,2 @@ done: false, | ||
}; | ||
export class AbstractVirtualTimeSchedulerResource extends AbstractSchedulerResource { | ||
next() { | ||
throwIfDisposed(this); | ||
const hasMore = this.step(); | ||
return hasMore ? iteratorYield : iteratorDone; | ||
} | ||
return() { | ||
this.dispose(); | ||
return iteratorDone; | ||
} | ||
throw(e) { | ||
this.dispose; | ||
if (e !== undefined) { | ||
throw e; | ||
} | ||
return iteratorDone; | ||
} | ||
run() { | ||
throwIfDisposed(this); | ||
while (this.step()) { } | ||
this.dispose(); | ||
} | ||
} | ||
const comparator = (a, b) => { | ||
@@ -42,15 +19,62 @@ let diff = 0; | ||
}; | ||
class VirtualTimeSchedulerResourceImpl extends AbstractVirtualTimeSchedulerResource { | ||
class VirtualTimeSchedulerResourceImpl extends AbstractSchedulerResource { | ||
constructor(maxMicroTaskTicks) { | ||
super(); | ||
this.maxMicroTaskTicks = maxMicroTaskTicks; | ||
this.continuationResult = { continuation: this }; | ||
this.microTaskTicks = 0; | ||
this.now = 0; | ||
this.microTaskTicks = 0; | ||
this.taskIDCount = 0; | ||
this.taskQueue = createPriorityQueue(comparator); | ||
this.shouldYield = () => { | ||
const runShouldYield = this.runShouldYield; | ||
this.microTaskTicks++; | ||
return (this.microTaskTicks >= this.maxMicroTaskTicks || | ||
(runShouldYield !== undefined && runShouldYield())); | ||
}; | ||
} | ||
shouldCallbackYield(_) { | ||
this.microTaskTicks++; | ||
return this.microTaskTicks >= this.maxMicroTaskTicks; | ||
loop(shouldYield) { | ||
this.runShouldYield = shouldYield; | ||
while (this.step()) { | ||
if (shouldYield()) { | ||
this.runShouldYield = undefined; | ||
return this.continuationResult; | ||
} | ||
} | ||
this.runShouldYield = undefined; | ||
return; | ||
} | ||
loopFast() { | ||
while (this.step()) { } | ||
} | ||
next() { | ||
throwIfDisposed(this); | ||
const hasMore = this.step(); | ||
return hasMore ? iteratorYield : iteratorDone; | ||
} | ||
return() { | ||
this.dispose(); | ||
return iteratorDone; | ||
} | ||
run(shouldYield) { | ||
throwIfDisposed(this); | ||
if (this.maxMicroTaskTicks === Number.MAX_SAFE_INTEGER && | ||
shouldYield === undefined) { | ||
this.shouldYield = undefined; | ||
} | ||
let result; | ||
if (shouldYield !== undefined) { | ||
result = this.loop(shouldYield); | ||
} | ||
else { | ||
result = this.loopFast(); | ||
} | ||
if (result !== undefined) { | ||
return result; | ||
} | ||
else { | ||
this.dispose(); | ||
return; | ||
} | ||
} | ||
scheduleCallback(callback, delay = 0) { | ||
@@ -81,4 +105,11 @@ const disposable = createDisposable(); | ||
} | ||
throw(e) { | ||
this.dispose; | ||
if (e !== undefined) { | ||
throw e; | ||
} | ||
return iteratorDone; | ||
} | ||
} | ||
export const createVirtualTimeSchedulerResource = (maxMicroTaskTicks = Number.MAX_SAFE_INTEGER) => new VirtualTimeSchedulerResourceImpl(maxMicroTaskTicks); | ||
//# sourceMappingURL=virtualTimeScheduler.js.map |
export { createPrioritySchedulerResource, PrioritySchedulerLike, PrioritySchedulerResourceLike, } from "./internal/priorityScheduler"; | ||
export { createVirtualTimeSchedulerResource, VirtualTimeSchedulerResourceLike, } from "./internal/virtualTimeScheduler"; | ||
export { createSynchronousSchedulerResource } from "./internal/synchronousScheduler"; | ||
export { createSchedulerWithPriority } from "./internal/schedulerWithPriority"; | ||
export { AbstractScheduler, AbstractSchedulerResource, } from "./internal/abstractScheduler"; | ||
//# sourceMappingURL=index.d.ts.map |
import { DisposableLike, DisposableOrTeardown } from "@reactive-js/disposable"; | ||
import { SchedulerLike, SchedulerContinuationLike, SchedulerResourceLike } from "@reactive-js/scheduler"; | ||
export declare abstract class AbstractScheduler implements SchedulerLike { | ||
private currentDisposable; | ||
private startTime; | ||
private shouldYield; | ||
protected abstract shouldCallbackYield(startTime: number): boolean; | ||
protected abstract get shouldYield(): (() => boolean) | undefined; | ||
protected abstract scheduleCallback(callback: () => void, delay?: number): DisposableLike; | ||
@@ -9,0 +6,0 @@ abstract readonly now: number; |
@@ -1,14 +0,5 @@ | ||
import { SchedulerResourceLike } from "@reactive-js/scheduler"; | ||
import { AbstractSchedulerResource } from "./abstractScheduler"; | ||
export interface VirtualTimeSchedulerResourceLike extends SchedulerResourceLike, Iterator<void> { | ||
run(): void; | ||
import { SchedulerResourceLike, SchedulerContinuationLike } from "@reactive-js/scheduler"; | ||
export interface VirtualTimeSchedulerResourceLike extends SchedulerResourceLike, Iterator<void>, SchedulerContinuationLike { | ||
} | ||
export declare abstract class AbstractVirtualTimeSchedulerResource extends AbstractSchedulerResource { | ||
protected abstract step(): boolean; | ||
next(): IteratorResult<void>; | ||
return(): IteratorResult<void>; | ||
throw(e?: any): IteratorResult<void>; | ||
run(): void; | ||
} | ||
export declare const createVirtualTimeSchedulerResource: (maxMicroTaskTicks?: number) => VirtualTimeSchedulerResourceLike; | ||
//# sourceMappingURL=virtualTimeScheduler.d.ts.map |
@@ -21,6 +21,9 @@ [@reactive-js/schedulers](../README.md) › [AbstractScheduler](abstractscheduler.md) | ||
### Accessors | ||
* [shouldYield](abstractscheduler.md#protected-shouldyield) | ||
### Methods | ||
* [scheduleCallback](abstractscheduler.md#protected-abstract-schedulecallback) | ||
* [shouldCallbackYield](abstractscheduler.md#protected-abstract-shouldcallbackyield) | ||
@@ -33,2 +36,10 @@ ## Properties | ||
## Accessors | ||
### `Protected` shouldYield | ||
• **get shouldYield**(): *function | undefined* | ||
**Returns:** *function | undefined* | ||
## Methods | ||
@@ -49,15 +60,1 @@ | ||
**Returns:** *DisposableLike* | ||
___ | ||
### `Protected` `Abstract` shouldCallbackYield | ||
▸ **shouldCallbackYield**(`startTime`: number): *boolean* | ||
**Parameters:** | ||
Name | Type | | ||
------ | ------ | | ||
`startTime` | number | | ||
**Returns:** *boolean* |
@@ -22,6 +22,9 @@ [@reactive-js/schedulers](../README.md) › [AbstractSchedulerResource](abstractschedulerresource.md) | ||
### Accessors | ||
* [shouldYield](abstractschedulerresource.md#protected-shouldyield) | ||
### Methods | ||
* [scheduleCallback](abstractschedulerresource.md#protected-abstract-schedulecallback) | ||
* [shouldCallbackYield](abstractschedulerresource.md#protected-abstract-shouldcallbackyield) | ||
@@ -36,2 +39,12 @@ ## Properties | ||
## Accessors | ||
### `Protected` shouldYield | ||
• **get shouldYield**(): *function | undefined* | ||
*Inherited from [AbstractScheduler](abstractscheduler.md).[shouldYield](abstractscheduler.md#protected-shouldyield)* | ||
**Returns:** *function | undefined* | ||
## Methods | ||
@@ -54,17 +67,1 @@ | ||
**Returns:** *DisposableLike* | ||
___ | ||
### `Protected` `Abstract` shouldCallbackYield | ||
▸ **shouldCallbackYield**(`startTime`: number): *boolean* | ||
*Inherited from [AbstractScheduler](abstractscheduler.md).[shouldCallbackYield](abstractscheduler.md#protected-abstract-shouldcallbackyield)* | ||
**Parameters:** | ||
Name | Type | | ||
------ | ------ | | ||
`startTime` | number | | ||
**Returns:** *boolean* |
@@ -17,16 +17,4 @@ [@reactive-js/schedulers](../README.md) › [VirtualTimeSchedulerResourceLike](virtualtimeschedulerresourcelike.md) | ||
* SchedulerContinuationLike | ||
↳ **VirtualTimeSchedulerResourceLike** | ||
## Index | ||
### Methods | ||
* [run](virtualtimeschedulerresourcelike.md#run) | ||
## Methods | ||
### run | ||
▸ **run**(): *void* | ||
**Returns:** *void* |
@@ -22,3 +22,2 @@ [@reactive-js/schedulers](README.md) | ||
* [createSchedulerWithPriority](README.md#const-createschedulerwithpriority) | ||
* [createSynchronousSchedulerResource](README.md#const-createsynchronousschedulerresource) | ||
* [createVirtualTimeSchedulerResource](README.md#const-createvirtualtimeschedulerresource) | ||
@@ -57,10 +56,2 @@ | ||
### `Const` createSynchronousSchedulerResource | ||
▸ **createSynchronousSchedulerResource**(): *[VirtualTimeSchedulerResourceLike](interfaces/virtualtimeschedulerresourcelike.md)* | ||
**Returns:** *[VirtualTimeSchedulerResourceLike](interfaces/virtualtimeschedulerresourcelike.md)* | ||
___ | ||
### `Const` createVirtualTimeSchedulerResource | ||
@@ -67,0 +58,0 @@ |
{ | ||
"name": "@reactive-js/schedulers", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"main": "dist/cjs/index.js", | ||
@@ -41,4 +41,4 @@ "module": "dist/esm5/index.js", | ||
"dependencies": { | ||
"@reactive-js/disposable": "^0.0.19", | ||
"@reactive-js/scheduler": "^0.0.19" | ||
"@reactive-js/disposable": "^0.0.20", | ||
"@reactive-js/scheduler": "^0.0.20" | ||
}, | ||
@@ -70,3 +70,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "fe0fe2eb19f54f103e64a4679266e3aea4c62194" | ||
"gitHead": "d78cd2b94c3a6a1a4eac41b8c9ca81bd9b98167d" | ||
} |
@@ -12,4 +12,2 @@ export { | ||
export { createSynchronousSchedulerResource } from "./internal/synchronousScheduler"; | ||
export { createSchedulerWithPriority } from "./internal/schedulerWithPriority"; | ||
@@ -16,0 +14,0 @@ |
import { | ||
createDisposable, | ||
createSerialDisposable, | ||
disposed, | ||
DisposableLike, | ||
@@ -17,10 +16,4 @@ DisposableOrTeardown, | ||
export abstract class AbstractScheduler implements SchedulerLike { | ||
private currentDisposable: DisposableLike = disposed; | ||
private startTime = 0; | ||
private shouldYield = () => | ||
this.currentDisposable.isDisposed || | ||
this.shouldCallbackYield(this.startTime); | ||
protected abstract get shouldYield(): (() => boolean) | undefined; | ||
protected abstract shouldCallbackYield(startTime: number): boolean; | ||
protected abstract scheduleCallback( | ||
@@ -39,6 +32,3 @@ callback: () => void, | ||
if (!disposable.isDisposed) { | ||
this.startTime = this.now; | ||
this.currentDisposable = disposable; | ||
const result = continuation.run(this.shouldYield) || undefined; | ||
this.currentDisposable = disposed; | ||
@@ -45,0 +35,0 @@ if (result !== undefined) { |
@@ -109,3 +109,3 @@ import { | ||
run(shouldYield: () => boolean) { | ||
run(shouldYield?: () => boolean) { | ||
for ( | ||
@@ -151,8 +151,12 @@ let currentTask = this.queue.peek(); | ||
const nextTask = this.queue.peek(); | ||
if (nextTask !== undefined && shouldYield()) { | ||
if (nextTask !== undefined) { | ||
const now = this.now; | ||
return { | ||
continuation: this, | ||
delay: Math.max(nextTask.dueTime - now, 0), | ||
}; | ||
const nextTaskDelay = Math.max(nextTask.dueTime - now, 0); | ||
if (nextTaskDelay > 0 || (shouldYield !== undefined && shouldYield())) { | ||
return { | ||
continuation: this, | ||
delay: nextTaskDelay, | ||
}; | ||
} | ||
} | ||
@@ -159,0 +163,0 @@ } |
@@ -6,5 +6,9 @@ import { | ||
} from "@reactive-js/disposable"; | ||
import { SchedulerResourceLike } from "@reactive-js/scheduler"; | ||
import { | ||
SchedulerResourceLike, | ||
SchedulerContinuationLike, | ||
SchedulerContinuationResultLike, | ||
} from "@reactive-js/scheduler"; | ||
import { AbstractSchedulerResource } from "./abstractScheduler"; | ||
import { createPriorityQueue, PriorityQueueLike } from "./priorityQueue"; | ||
import { AbstractSchedulerResource } from "./abstractScheduler"; | ||
@@ -14,5 +18,4 @@ /** @noInheritDoc */ | ||
extends SchedulerResourceLike, | ||
Iterator<void> { | ||
run(): void; | ||
} | ||
Iterator<void>, | ||
SchedulerContinuationLike {} | ||
@@ -29,35 +32,2 @@ const iteratorYield = { | ||
/** @ignore */ | ||
export abstract class AbstractVirtualTimeSchedulerResource extends AbstractSchedulerResource { | ||
protected abstract step(): boolean; | ||
next(): IteratorResult<void> { | ||
throwIfDisposed(this); | ||
const hasMore = this.step(); | ||
return hasMore ? iteratorYield : iteratorDone; | ||
} | ||
return(): IteratorResult<void> { | ||
this.dispose(); | ||
return iteratorDone; | ||
} | ||
throw(e?: any): IteratorResult<void> { | ||
this.dispose; | ||
if (e !== undefined) { | ||
throw e; | ||
} | ||
return iteratorDone; | ||
} | ||
run() { | ||
throwIfDisposed(this); | ||
// eslint-disable-next-line no-empty | ||
while (this.step()) {} | ||
this.dispose(); | ||
} | ||
} | ||
interface VirtualTask { | ||
@@ -77,7 +47,8 @@ callback: () => void; | ||
class VirtualTimeSchedulerResourceImpl | ||
extends AbstractVirtualTimeSchedulerResource | ||
class VirtualTimeSchedulerResourceImpl extends AbstractSchedulerResource | ||
implements VirtualTimeSchedulerResourceLike { | ||
private readonly continuationResult = { continuation: this }; | ||
private microTaskTicks = 0; | ||
now = 0; | ||
private microTaskTicks = 0; | ||
private runShouldYield?: () => boolean; | ||
private taskIDCount = 0; | ||
@@ -88,2 +59,11 @@ private readonly taskQueue: PriorityQueueLike< | ||
protected shouldYield: (() => boolean) | undefined = () => { | ||
const runShouldYield = this.runShouldYield; | ||
this.microTaskTicks++; | ||
return ( | ||
this.microTaskTicks >= this.maxMicroTaskTicks || | ||
(runShouldYield !== undefined && runShouldYield()) | ||
); | ||
}; | ||
constructor(private readonly maxMicroTaskTicks: number) { | ||
@@ -93,7 +73,59 @@ super(); | ||
protected shouldCallbackYield(_: number): boolean { | ||
this.microTaskTicks++; | ||
return this.microTaskTicks >= this.maxMicroTaskTicks; | ||
private loop( | ||
shouldYield: () => boolean, | ||
): SchedulerContinuationResultLike | void { | ||
this.runShouldYield = shouldYield; | ||
while (this.step()) { | ||
if (shouldYield()) { | ||
this.runShouldYield = undefined; | ||
return this.continuationResult; | ||
} | ||
} | ||
this.runShouldYield = undefined; | ||
return; | ||
} | ||
private loopFast() { | ||
// eslint-disable-next-line no-empty | ||
while (this.step()) {} | ||
} | ||
next(): IteratorResult<void> { | ||
throwIfDisposed(this); | ||
const hasMore = this.step(); | ||
return hasMore ? iteratorYield : iteratorDone; | ||
} | ||
return(): IteratorResult<void> { | ||
this.dispose(); | ||
return iteratorDone; | ||
} | ||
run(shouldYield?: () => boolean): SchedulerContinuationResultLike | void { | ||
throwIfDisposed(this); | ||
if ( | ||
this.maxMicroTaskTicks === Number.MAX_SAFE_INTEGER && | ||
shouldYield === undefined | ||
) { | ||
this.shouldYield = undefined; | ||
} | ||
let result: SchedulerContinuationResultLike | void; | ||
if (shouldYield !== undefined) { | ||
result = this.loop(shouldYield); | ||
} else { | ||
result = this.loopFast(); | ||
} | ||
if (result !== undefined) { | ||
return result; | ||
} else { | ||
this.dispose(); | ||
return; | ||
} | ||
} | ||
protected scheduleCallback(callback: () => void, delay = 0): DisposableLike { | ||
@@ -113,3 +145,3 @@ const disposable = createDisposable(); | ||
protected step(): boolean { | ||
private step(): boolean { | ||
const task = this.taskQueue.pop(); | ||
@@ -131,2 +163,10 @@ | ||
} | ||
throw(e?: any): IteratorResult<void> { | ||
this.dispose; | ||
if (e !== undefined) { | ||
throw e; | ||
} | ||
return iteratorDone; | ||
} | ||
} | ||
@@ -133,0 +173,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
Sorry, the diff of this file is not supported yet
426076
72
1490
+ Added@reactive-js/disposable@0.0.20(transitive)
+ Added@reactive-js/scheduler@0.0.20(transitive)
- Removed@reactive-js/disposable@0.0.19(transitive)
- Removed@reactive-js/scheduler@0.0.19(transitive)