@most/scheduler
Advanced tools
Comparing version 0.7.1 to 0.8.0
@@ -48,6 +48,20 @@ /** @license MIT License (c) copyright 2010-2016 original author or authors */ | ||
// curry3 :: ((a, b, c) -> d) -> (a -> b -> c -> d) | ||
function curry3 (f) { | ||
function curried (a, b, c) { // eslint-disable-line complexity | ||
switch (arguments.length) { | ||
case 0: return curried | ||
case 1: return curry2(function (b, c) { return f(a, b, c); }) | ||
case 2: return function (c) { return f(a, b, c); } | ||
default:return f(a, b, c) | ||
} | ||
} | ||
return curried | ||
} | ||
/** @license MIT License (c) copyright 2010-2017 original author or authors */ | ||
function ScheduledTask (delay, period, task, scheduler) { | ||
this.time = delay; | ||
var ScheduledTask = function ScheduledTask (time, localOffset, period, task, scheduler) { | ||
this.time = time; | ||
this.localOffset = localOffset; | ||
this.period = period; | ||
@@ -57,13 +71,13 @@ this.task = task; | ||
this.active = true; | ||
} | ||
}; | ||
ScheduledTask.prototype.run = function () { | ||
return this.task.run(this.time) | ||
ScheduledTask.prototype.run = function run () { | ||
return this.task.run(this.time - this.localOffset) | ||
}; | ||
ScheduledTask.prototype.error = function (e) { | ||
return this.task.error(this.time, e) | ||
ScheduledTask.prototype.error = function error (e) { | ||
return this.task.error(this.time - this.localOffset, e) | ||
}; | ||
ScheduledTask.prototype.dispose = function () { | ||
ScheduledTask.prototype.dispose = function dispose () { | ||
this.scheduler.cancel(this); | ||
@@ -73,2 +87,59 @@ return this.task.dispose() | ||
// AbstractScheduler should not be exposed publicly | ||
// Temporary mixin to reduce duplication between | ||
// Scheduler and RelativeScheduler. Eventually, | ||
// the Scheduler interface will change and this | ||
// can be removed. | ||
var AbstractScheduler = function AbstractScheduler () {}; | ||
AbstractScheduler.prototype.asap = function asap (task) { | ||
return this.scheduleTask(0, 0, -1, task) | ||
}; | ||
AbstractScheduler.prototype.delay = function delay (delay$1, task) { | ||
return this.scheduleTask(0, delay$1, -1, task) | ||
}; | ||
AbstractScheduler.prototype.periodic = function periodic (period, task) { | ||
return this.scheduleTask(0, 0, period, task) | ||
}; | ||
AbstractScheduler.prototype.schedule = function schedule (delay, period, task) { | ||
return this.scheduleTask(0, delay, period, task) | ||
}; | ||
var RelativeScheduler = (function (AbstractScheduler$$1) { | ||
function RelativeScheduler (origin, scheduler) { | ||
AbstractScheduler$$1.call(this); | ||
this.origin = origin; | ||
this.scheduler = scheduler; | ||
} | ||
if ( AbstractScheduler$$1 ) RelativeScheduler.__proto__ = AbstractScheduler$$1; | ||
RelativeScheduler.prototype = Object.create( AbstractScheduler$$1 && AbstractScheduler$$1.prototype ); | ||
RelativeScheduler.prototype.constructor = RelativeScheduler; | ||
RelativeScheduler.prototype.now = function now () { | ||
return this.scheduler.now() - this.origin | ||
}; | ||
RelativeScheduler.prototype.scheduleTask = function scheduleTask (localOffset, delay, period, task) { | ||
return this.scheduler.scheduleTask(localOffset + this.origin, delay, period, task) | ||
}; | ||
RelativeScheduler.prototype.relative = function relative (origin) { | ||
return new RelativeScheduler(origin + this.origin, this.scheduler) | ||
}; | ||
RelativeScheduler.prototype.cancel = function cancel (task) { | ||
return this.scheduler.cancel(task) | ||
}; | ||
RelativeScheduler.prototype.cancelAll = function cancelAll (f) { | ||
return this.scheduler.cancelAll(f) | ||
}; | ||
return RelativeScheduler; | ||
}(AbstractScheduler)); | ||
/** @license MIT License (c) copyright 2010-2017 original author or authors */ | ||
@@ -88,90 +159,91 @@ | ||
var Scheduler = function Scheduler (timer, timeline) { | ||
var this$1 = this; | ||
var Scheduler = (function (AbstractScheduler$$1) { | ||
function Scheduler (timer, timeline) { | ||
var this$1 = this; | ||
this.timer = timer; | ||
this.timeline = timeline; | ||
AbstractScheduler$$1.call(this); | ||
this.timer = timer; | ||
this.timeline = timeline; | ||
this._timer = null; | ||
this._nextArrival = Infinity; | ||
this._timer = null; | ||
this._nextArrival = Infinity; | ||
this._runReadyTasksBound = function () { return this$1._runReadyTasks(this$1.now()); }; | ||
}; | ||
this._runReadyTasksBound = function () { return this$1._runReadyTasks(this$1.now()); }; | ||
} | ||
Scheduler.prototype.now = function now () { | ||
return this.timer.now() | ||
}; | ||
if ( AbstractScheduler$$1 ) Scheduler.__proto__ = AbstractScheduler$$1; | ||
Scheduler.prototype = Object.create( AbstractScheduler$$1 && AbstractScheduler$$1.prototype ); | ||
Scheduler.prototype.constructor = Scheduler; | ||
Scheduler.prototype.asap = function asap (task) { | ||
return this.schedule(0, -1, task) | ||
}; | ||
Scheduler.prototype.now = function now () { | ||
return this.timer.now() | ||
}; | ||
Scheduler.prototype.delay = function delay (delay$1, task) { | ||
return this.schedule(delay$1, -1, task) | ||
}; | ||
Scheduler.prototype.scheduleTask = function scheduleTask (localOffset, delay, period, task) { | ||
var time = this.now() + Math.max(0, delay); | ||
var st = new ScheduledTask(time, localOffset, period, task, this); | ||
Scheduler.prototype.periodic = function periodic (period, task) { | ||
return this.schedule(0, period, task) | ||
}; | ||
this.timeline.add(st); | ||
this._scheduleNextRun(); | ||
return st | ||
}; | ||
Scheduler.prototype.schedule = function schedule (delay, period, task) { | ||
var now = this.now(); | ||
var st = new ScheduledTask(now + Math.max(0, delay), period, task, this); | ||
Scheduler.prototype.relative = function relative (offset) { | ||
return new RelativeScheduler(offset, this) | ||
}; | ||
this.timeline.add(st); | ||
this._scheduleNextRun(now); | ||
return st | ||
}; | ||
Scheduler.prototype.cancel = function cancel (task) { | ||
task.active = false; | ||
if (this.timeline.remove(task)) { | ||
this._reschedule(); | ||
} | ||
}; | ||
Scheduler.prototype.cancel = function cancel (task) { | ||
task.active = false; | ||
if (this.timeline.remove(task)) { | ||
Scheduler.prototype.cancelAll = function cancelAll (f) { | ||
this.timeline.removeAll(f); | ||
this._reschedule(); | ||
} | ||
}; | ||
}; | ||
Scheduler.prototype.cancelAll = function cancelAll (f) { | ||
this.timeline.removeAll(f); | ||
this._reschedule(); | ||
}; | ||
Scheduler.prototype._reschedule = function _reschedule () { | ||
if (this.timeline.isEmpty()) { | ||
this._unschedule(); | ||
} else { | ||
this._scheduleNextRun(this.now()); | ||
} | ||
}; | ||
Scheduler.prototype._reschedule = function _reschedule () { | ||
if (this.timeline.isEmpty()) { | ||
this._unschedule(); | ||
} else { | ||
this._scheduleNextRun(this.now()); | ||
} | ||
}; | ||
Scheduler.prototype._unschedule = function _unschedule () { | ||
this.timer.clearTimer(this._timer); | ||
this._timer = null; | ||
}; | ||
Scheduler.prototype._unschedule = function _unschedule () { | ||
this.timer.clearTimer(this._timer); | ||
this._timer = null; | ||
}; | ||
Scheduler.prototype._scheduleNextRun = function _scheduleNextRun () { // eslint-disable-line complexity | ||
if (this.timeline.isEmpty()) { | ||
return | ||
} | ||
Scheduler.prototype._scheduleNextRun = function _scheduleNextRun (now) { // eslint-disable-line complexity | ||
if (this.timeline.isEmpty()) { | ||
return | ||
} | ||
var nextArrival = this.timeline.nextArrival(); | ||
var nextArrival = this.timeline.nextArrival(); | ||
if (this._timer === null) { | ||
this._scheduleNextArrival(nextArrival); | ||
} else if (nextArrival < this._nextArrival) { | ||
this._unschedule(); | ||
this._scheduleNextArrival(nextArrival); | ||
} | ||
}; | ||
if (this._timer === null) { | ||
this._scheduleNextArrival(nextArrival, now); | ||
} else if (nextArrival < this._nextArrival) { | ||
this._unschedule(); | ||
this._scheduleNextArrival(nextArrival, now); | ||
} | ||
}; | ||
Scheduler.prototype._scheduleNextArrival = function _scheduleNextArrival (nextArrival) { | ||
this._nextArrival = nextArrival; | ||
var delay = Math.max(0, nextArrival - this.now()); | ||
this._timer = this.timer.setTimer(this._runReadyTasksBound, delay); | ||
}; | ||
Scheduler.prototype._scheduleNextArrival = function _scheduleNextArrival (nextArrival, now) { | ||
this._nextArrival = nextArrival; | ||
var delay = Math.max(0, nextArrival - now); | ||
this._timer = this.timer.setTimer(this._runReadyTasksBound, delay); | ||
}; | ||
Scheduler.prototype._runReadyTasks = function _runReadyTasks () { | ||
this._timer = null; | ||
this.timeline.runTasks(this.now(), runTask); | ||
this._scheduleNextRun(); | ||
}; | ||
Scheduler.prototype._runReadyTasks = function _runReadyTasks (now) { | ||
this._timer = null; | ||
this.timeline.runTasks(now, runTask); | ||
this._scheduleNextRun(this.now()); | ||
}; | ||
return Scheduler; | ||
}(AbstractScheduler)); | ||
@@ -414,2 +486,15 @@ /** @license MIT License (c) copyright 2010-2017 original author or authors */ | ||
// Schedule a task to run as soon as possible, but | ||
// not in the current call stack | ||
var asap = curry2(function (task, scheduler) { return scheduler.asap(task); }); | ||
// Schedule a task to run after a millisecond delay | ||
var delay = curry3(function (delay, task, scheduler) { return scheduler.delay(delay, task); }); | ||
// Schedule a task to run periodically, with the | ||
// first run starting asap | ||
var periodic = curry3(function (period, task, scheduler) { return scheduler.periodic(period, task); }); | ||
var schedulerRelativeTo = curry2(function (offset, scheduler) { return new RelativeScheduler(offset, scheduler); }); | ||
/** @license MIT License (c) copyright 2010-2017 original author or authors */ | ||
@@ -426,3 +511,3 @@ | ||
export { newScheduler, newDefaultScheduler, newDefaultTimer, newClockTimer, newTimeline, RelativeClock, HRTimeClock, clockRelativeTo, newPerformanceClock, newDateClock, newHRTimeClock, newPlatformClock }; | ||
export { newScheduler, newDefaultScheduler, newDefaultTimer, newClockTimer, newTimeline, RelativeClock, HRTimeClock, clockRelativeTo, newPerformanceClock, newDateClock, newHRTimeClock, newPlatformClock, asap, delay, periodic, schedulerRelativeTo }; | ||
//# sourceMappingURL=index.es.js.map |
@@ -54,6 +54,20 @@ (function (global, factory) { | ||
// curry3 :: ((a, b, c) -> d) -> (a -> b -> c -> d) | ||
function curry3 (f) { | ||
function curried (a, b, c) { // eslint-disable-line complexity | ||
switch (arguments.length) { | ||
case 0: return curried | ||
case 1: return curry2(function (b, c) { return f(a, b, c); }) | ||
case 2: return function (c) { return f(a, b, c); } | ||
default:return f(a, b, c) | ||
} | ||
} | ||
return curried | ||
} | ||
/** @license MIT License (c) copyright 2010-2017 original author or authors */ | ||
function ScheduledTask (delay, period, task, scheduler) { | ||
this.time = delay; | ||
var ScheduledTask = function ScheduledTask (time, localOffset, period, task, scheduler) { | ||
this.time = time; | ||
this.localOffset = localOffset; | ||
this.period = period; | ||
@@ -63,13 +77,13 @@ this.task = task; | ||
this.active = true; | ||
} | ||
}; | ||
ScheduledTask.prototype.run = function () { | ||
return this.task.run(this.time) | ||
ScheduledTask.prototype.run = function run () { | ||
return this.task.run(this.time - this.localOffset) | ||
}; | ||
ScheduledTask.prototype.error = function (e) { | ||
return this.task.error(this.time, e) | ||
ScheduledTask.prototype.error = function error (e) { | ||
return this.task.error(this.time - this.localOffset, e) | ||
}; | ||
ScheduledTask.prototype.dispose = function () { | ||
ScheduledTask.prototype.dispose = function dispose () { | ||
this.scheduler.cancel(this); | ||
@@ -79,2 +93,59 @@ return this.task.dispose() | ||
// AbstractScheduler should not be exposed publicly | ||
// Temporary mixin to reduce duplication between | ||
// Scheduler and RelativeScheduler. Eventually, | ||
// the Scheduler interface will change and this | ||
// can be removed. | ||
var AbstractScheduler = function AbstractScheduler () {}; | ||
AbstractScheduler.prototype.asap = function asap (task) { | ||
return this.scheduleTask(0, 0, -1, task) | ||
}; | ||
AbstractScheduler.prototype.delay = function delay (delay$1, task) { | ||
return this.scheduleTask(0, delay$1, -1, task) | ||
}; | ||
AbstractScheduler.prototype.periodic = function periodic (period, task) { | ||
return this.scheduleTask(0, 0, period, task) | ||
}; | ||
AbstractScheduler.prototype.schedule = function schedule (delay, period, task) { | ||
return this.scheduleTask(0, delay, period, task) | ||
}; | ||
var RelativeScheduler = (function (AbstractScheduler$$1) { | ||
function RelativeScheduler (origin, scheduler) { | ||
AbstractScheduler$$1.call(this); | ||
this.origin = origin; | ||
this.scheduler = scheduler; | ||
} | ||
if ( AbstractScheduler$$1 ) RelativeScheduler.__proto__ = AbstractScheduler$$1; | ||
RelativeScheduler.prototype = Object.create( AbstractScheduler$$1 && AbstractScheduler$$1.prototype ); | ||
RelativeScheduler.prototype.constructor = RelativeScheduler; | ||
RelativeScheduler.prototype.now = function now () { | ||
return this.scheduler.now() - this.origin | ||
}; | ||
RelativeScheduler.prototype.scheduleTask = function scheduleTask (localOffset, delay, period, task) { | ||
return this.scheduler.scheduleTask(localOffset + this.origin, delay, period, task) | ||
}; | ||
RelativeScheduler.prototype.relative = function relative (origin) { | ||
return new RelativeScheduler(origin + this.origin, this.scheduler) | ||
}; | ||
RelativeScheduler.prototype.cancel = function cancel (task) { | ||
return this.scheduler.cancel(task) | ||
}; | ||
RelativeScheduler.prototype.cancelAll = function cancelAll (f) { | ||
return this.scheduler.cancelAll(f) | ||
}; | ||
return RelativeScheduler; | ||
}(AbstractScheduler)); | ||
/** @license MIT License (c) copyright 2010-2017 original author or authors */ | ||
@@ -94,90 +165,91 @@ | ||
var Scheduler = function Scheduler (timer, timeline) { | ||
var this$1 = this; | ||
var Scheduler = (function (AbstractScheduler$$1) { | ||
function Scheduler (timer, timeline) { | ||
var this$1 = this; | ||
this.timer = timer; | ||
this.timeline = timeline; | ||
AbstractScheduler$$1.call(this); | ||
this.timer = timer; | ||
this.timeline = timeline; | ||
this._timer = null; | ||
this._nextArrival = Infinity; | ||
this._timer = null; | ||
this._nextArrival = Infinity; | ||
this._runReadyTasksBound = function () { return this$1._runReadyTasks(this$1.now()); }; | ||
}; | ||
this._runReadyTasksBound = function () { return this$1._runReadyTasks(this$1.now()); }; | ||
} | ||
Scheduler.prototype.now = function now () { | ||
return this.timer.now() | ||
}; | ||
if ( AbstractScheduler$$1 ) Scheduler.__proto__ = AbstractScheduler$$1; | ||
Scheduler.prototype = Object.create( AbstractScheduler$$1 && AbstractScheduler$$1.prototype ); | ||
Scheduler.prototype.constructor = Scheduler; | ||
Scheduler.prototype.asap = function asap (task) { | ||
return this.schedule(0, -1, task) | ||
}; | ||
Scheduler.prototype.now = function now () { | ||
return this.timer.now() | ||
}; | ||
Scheduler.prototype.delay = function delay (delay$1, task) { | ||
return this.schedule(delay$1, -1, task) | ||
}; | ||
Scheduler.prototype.scheduleTask = function scheduleTask (localOffset, delay, period, task) { | ||
var time = this.now() + Math.max(0, delay); | ||
var st = new ScheduledTask(time, localOffset, period, task, this); | ||
Scheduler.prototype.periodic = function periodic (period, task) { | ||
return this.schedule(0, period, task) | ||
}; | ||
this.timeline.add(st); | ||
this._scheduleNextRun(); | ||
return st | ||
}; | ||
Scheduler.prototype.schedule = function schedule (delay, period, task) { | ||
var now = this.now(); | ||
var st = new ScheduledTask(now + Math.max(0, delay), period, task, this); | ||
Scheduler.prototype.relative = function relative (offset) { | ||
return new RelativeScheduler(offset, this) | ||
}; | ||
this.timeline.add(st); | ||
this._scheduleNextRun(now); | ||
return st | ||
}; | ||
Scheduler.prototype.cancel = function cancel (task) { | ||
task.active = false; | ||
if (this.timeline.remove(task)) { | ||
this._reschedule(); | ||
} | ||
}; | ||
Scheduler.prototype.cancel = function cancel (task) { | ||
task.active = false; | ||
if (this.timeline.remove(task)) { | ||
Scheduler.prototype.cancelAll = function cancelAll (f) { | ||
this.timeline.removeAll(f); | ||
this._reschedule(); | ||
} | ||
}; | ||
}; | ||
Scheduler.prototype.cancelAll = function cancelAll (f) { | ||
this.timeline.removeAll(f); | ||
this._reschedule(); | ||
}; | ||
Scheduler.prototype._reschedule = function _reschedule () { | ||
if (this.timeline.isEmpty()) { | ||
this._unschedule(); | ||
} else { | ||
this._scheduleNextRun(this.now()); | ||
} | ||
}; | ||
Scheduler.prototype._reschedule = function _reschedule () { | ||
if (this.timeline.isEmpty()) { | ||
this._unschedule(); | ||
} else { | ||
this._scheduleNextRun(this.now()); | ||
} | ||
}; | ||
Scheduler.prototype._unschedule = function _unschedule () { | ||
this.timer.clearTimer(this._timer); | ||
this._timer = null; | ||
}; | ||
Scheduler.prototype._unschedule = function _unschedule () { | ||
this.timer.clearTimer(this._timer); | ||
this._timer = null; | ||
}; | ||
Scheduler.prototype._scheduleNextRun = function _scheduleNextRun () { // eslint-disable-line complexity | ||
if (this.timeline.isEmpty()) { | ||
return | ||
} | ||
Scheduler.prototype._scheduleNextRun = function _scheduleNextRun (now) { // eslint-disable-line complexity | ||
if (this.timeline.isEmpty()) { | ||
return | ||
} | ||
var nextArrival = this.timeline.nextArrival(); | ||
var nextArrival = this.timeline.nextArrival(); | ||
if (this._timer === null) { | ||
this._scheduleNextArrival(nextArrival); | ||
} else if (nextArrival < this._nextArrival) { | ||
this._unschedule(); | ||
this._scheduleNextArrival(nextArrival); | ||
} | ||
}; | ||
if (this._timer === null) { | ||
this._scheduleNextArrival(nextArrival, now); | ||
} else if (nextArrival < this._nextArrival) { | ||
this._unschedule(); | ||
this._scheduleNextArrival(nextArrival, now); | ||
} | ||
}; | ||
Scheduler.prototype._scheduleNextArrival = function _scheduleNextArrival (nextArrival) { | ||
this._nextArrival = nextArrival; | ||
var delay = Math.max(0, nextArrival - this.now()); | ||
this._timer = this.timer.setTimer(this._runReadyTasksBound, delay); | ||
}; | ||
Scheduler.prototype._scheduleNextArrival = function _scheduleNextArrival (nextArrival, now) { | ||
this._nextArrival = nextArrival; | ||
var delay = Math.max(0, nextArrival - now); | ||
this._timer = this.timer.setTimer(this._runReadyTasksBound, delay); | ||
}; | ||
Scheduler.prototype._runReadyTasks = function _runReadyTasks () { | ||
this._timer = null; | ||
this.timeline.runTasks(this.now(), runTask); | ||
this._scheduleNextRun(); | ||
}; | ||
Scheduler.prototype._runReadyTasks = function _runReadyTasks (now) { | ||
this._timer = null; | ||
this.timeline.runTasks(now, runTask); | ||
this._scheduleNextRun(this.now()); | ||
}; | ||
return Scheduler; | ||
}(AbstractScheduler)); | ||
@@ -420,2 +492,15 @@ /** @license MIT License (c) copyright 2010-2017 original author or authors */ | ||
// Schedule a task to run as soon as possible, but | ||
// not in the current call stack | ||
var asap = curry2(function (task, scheduler) { return scheduler.asap(task); }); | ||
// Schedule a task to run after a millisecond delay | ||
var delay = curry3(function (delay, task, scheduler) { return scheduler.delay(delay, task); }); | ||
// Schedule a task to run periodically, with the | ||
// first run starting asap | ||
var periodic = curry3(function (period, task, scheduler) { return scheduler.periodic(period, task); }); | ||
var schedulerRelativeTo = curry2(function (offset, scheduler) { return new RelativeScheduler(offset, scheduler); }); | ||
/** @license MIT License (c) copyright 2010-2017 original author or authors */ | ||
@@ -444,2 +529,6 @@ | ||
exports.newPlatformClock = newPlatformClock; | ||
exports.asap = asap; | ||
exports.delay = delay; | ||
exports.periodic = periodic; | ||
exports.schedulerRelativeTo = schedulerRelativeTo; | ||
@@ -446,0 +535,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -1,1 +0,1 @@ | ||
(function(t,e){typeof exports==="object"&&typeof module!=="undefined"?e(exports):typeof define==="function"&&define.amd?define(["exports"],e):e(t.mostCore=t.mostCore||{})})(this,function(t){"use strict";function e(t,e){var n=e.length;var r=new Array(n);var i=0;for(var o,s=0;s<n;++s){o=e[s];if(!t(o)){r[i]=o;++i}}r.length=i;return r}function n(t,e){for(var n=0,r=e.length;n<r;++n){if(t===e[n]){return n}}return-1}function r(t){function e(n,r){switch(arguments.length){case 0:return e;case 1:return function(e){return t(n,e)};default:return t(n,r)}}return e}function i(t,e,n,r){this.time=t;this.period=e;this.task=n;this.scheduler=r;this.active=true}i.prototype.run=function(){return this.task.run(this.time)};i.prototype.error=function(t){return this.task.error(this.time,t)};i.prototype.dispose=function(){this.scheduler.cancel(this);return this.task.dispose()};var o=function(t){return Promise.resolve(t).then(s)};function s(t){try{return t.run()}catch(e){return t.error(e)}}var u=function t(e,n){var r=this;this.timer=e;this.timeline=n;this._timer=null;this._nextArrival=Infinity;this._runReadyTasksBound=function(){return r._runReadyTasks(r.now())}};u.prototype.now=function t(){return this.timer.now()};u.prototype.asap=function t(e){return this.schedule(0,-1,e)};u.prototype.delay=function t(e,n){return this.schedule(e,-1,n)};u.prototype.periodic=function t(e,n){return this.schedule(0,e,n)};u.prototype.schedule=function t(e,n,r){var o=this.now();var s=new i(o+Math.max(0,e),n,r,this);this.timeline.add(s);this._scheduleNextRun(o);return s};u.prototype.cancel=function t(e){e.active=false;if(this.timeline.remove(e)){this._reschedule()}};u.prototype.cancelAll=function t(e){this.timeline.removeAll(e);this._reschedule()};u.prototype._reschedule=function t(){if(this.timeline.isEmpty()){this._unschedule()}else{this._scheduleNextRun(this.now())}};u.prototype._unschedule=function t(){this.timer.clearTimer(this._timer);this._timer=null};u.prototype._scheduleNextRun=function t(e){if(this.timeline.isEmpty()){return}var n=this.timeline.nextArrival();if(this._timer===null){this._scheduleNextArrival(n,e)}else if(n<this._nextArrival){this._unschedule();this._scheduleNextArrival(n,e)}};u.prototype._scheduleNextArrival=function t(e,n){this._nextArrival=e;var r=Math.max(0,e-n);this._timer=this.timer.setTimer(this._runReadyTasksBound,r)};u.prototype._runReadyTasks=function t(e){this._timer=null;this.timeline.runTasks(e,s);this._scheduleNextRun(this.now())};var c=function t(){this.tasks=[]};c.prototype.nextArrival=function t(){return this.isEmpty()?Infinity:this.tasks[0].time};c.prototype.isEmpty=function t(){return this.tasks.length===0};c.prototype.add=function t(e){a(e,this.tasks)};c.prototype.remove=function t(e){var r=d(v(e),this.tasks);if(r>=0&&r<this.tasks.length){var i=n(e,this.tasks[r].events);if(i>=0){this.tasks[r].events.splice(i,1);return true}}return false};c.prototype.removeAll=function t(e){var n=this;for(var r=0;r<this.tasks.length;++r){m(e,n.tasks[r])}};c.prototype.runTasks=function t(e,n){var r=this;var i=this.tasks;var o=i.length;var s=0;while(s<o&&i[s].time<=e){++s}this.tasks=i.slice(s);for(var u=0;u<s;++u){r.tasks=h(n,i[u].events,r.tasks)}};function h(t,e,n){for(var r=0;r<e.length;++r){var i=e[r];if(i.active){t(i);if(i.period>=0&&i.active){i.time=i.time+i.period;a(i,n)}}}return n}function a(t,e){var n=e.length;var r=v(t);if(n===0){e.push(y(r,[t]));return}var i=d(r,e);if(i>=n){e.push(y(r,[t]))}else{f(t,e,r,i)}}function f(t,e,n,r){var i=e[r];if(n===i.time){l(t,i.events,n)}else{e.splice(r,0,y(n,[t]))}}function l(t,e){if(e.length===0||t.time>=e[e.length-1].time){e.push(t)}else{p(t,e)}}function p(t,e){for(var n=0;n<e.length;n++){if(t.time<e[n].time){e.splice(n,0,t);break}}}function v(t){return Math.floor(t.time)}function m(t,n){n.events=e(t,n.events)}function d(t,e){var n=0;var r=e.length;var i,o;while(n<r){i=Math.floor((n+r)/2);o=e[i];if(t===o.time){return i}else if(t<o.time){r=i}else{n=i+1}}return r}var y=function(t,e){return{time:t,events:e}};var k=function t(e){this._clock=e};k.prototype.now=function t(){return this._clock.now()};k.prototype.setTimer=function t(e,n){return n<=0?_(e):setTimeout(e,n)};k.prototype.clearTimer=function t(e){return e instanceof w?e.cancel():clearTimeout(e)};var w=function t(e){this.f=e;this.active=true};w.prototype.run=function t(){return this.active&&this.f()};w.prototype.error=function t(e){throw e};w.prototype.cancel=function t(){this.active=false};function _(t){var e=new w(t);o(e);return e}var g=function t(e,n){this.origin=n;this.clock=e};g.prototype.now=function t(){return this.clock.now()-this.origin};var T=function t(e,n){this.origin=n;this.hrtime=e};T.prototype.now=function t(){var e=this.hrtime(this.origin);return(e[0]*1e9+e[1])/1e6};var x=function(t){return new g(t,t.now())};var A=function(){return x(performance)};var R=function(){return x(Date)};var C=function(){return new T(process.hrtime,process.hrtime())};var N=function(){if(typeof performance!=="undefined"&&typeof performance.now==="function"){return A()}else if(typeof process!=="undefined"&&typeof process.hrtime==="function"){return C()}return R()};var M=r(function(t,e){return new u(t,e)});var D=function(){return new u(E(),new c)};var E=function(){return new k(N())};var P=function(t){return new k(t)};var b=function(){return new c};t.newScheduler=M;t.newDefaultScheduler=D;t.newDefaultTimer=E;t.newClockTimer=P;t.newTimeline=b;t.RelativeClock=g;t.HRTimeClock=T;t.clockRelativeTo=x;t.newPerformanceClock=A;t.newDateClock=R;t.newHRTimeClock=C;t.newPlatformClock=N;Object.defineProperty(t,"__esModule",{value:true})}); | ||
(function(t,e){typeof exports==="object"&&typeof module!=="undefined"?e(exports):typeof define==="function"&&define.amd?define(["exports"],e):e(t.mostCore=t.mostCore||{})})(this,function(t){"use strict";function e(t,e){var n=e.length;var r=new Array(n);var i=0;for(var o,s=0;s<n;++s){o=e[s];if(!t(o)){r[i]=o;++i}}r.length=i;return r}function n(t,e){for(var n=0,r=e.length;n<r;++n){if(t===e[n]){return n}}return-1}function r(t){function e(n,r){switch(arguments.length){case 0:return e;case 1:return function(e){return t(n,e)};default:return t(n,r)}}return e}function i(t){function e(n,i,o){switch(arguments.length){case 0:return e;case 1:return r(function(e,r){return t(n,e,r)});case 2:return function(e){return t(n,i,e)};default:return t(n,i,o)}}return e}var o=function t(e,n,r,i,o){this.time=e;this.localOffset=n;this.period=r;this.task=i;this.scheduler=o;this.active=true};o.prototype.run=function t(){return this.task.run(this.time-this.localOffset)};o.prototype.error=function t(e){return this.task.error(this.time-this.localOffset,e)};o.prototype.dispose=function t(){this.scheduler.cancel(this);return this.task.dispose()};var s=function t(){};s.prototype.asap=function t(e){return this.scheduleTask(0,0,-1,e)};s.prototype.delay=function t(e,n){return this.scheduleTask(0,e,-1,n)};s.prototype.periodic=function t(e,n){return this.scheduleTask(0,0,e,n)};s.prototype.schedule=function t(e,n,r){return this.scheduleTask(0,e,n,r)};var u=function(t){function e(e,n){t.call(this);this.origin=e;this.scheduler=n}if(t)e.__proto__=t;e.prototype=Object.create(t&&t.prototype);e.prototype.constructor=e;e.prototype.now=function t(){return this.scheduler.now()-this.origin};e.prototype.scheduleTask=function t(e,n,r,i){return this.scheduler.scheduleTask(e+this.origin,n,r,i)};e.prototype.relative=function t(n){return new e(n+this.origin,this.scheduler)};e.prototype.cancel=function t(e){return this.scheduler.cancel(e)};e.prototype.cancelAll=function t(e){return this.scheduler.cancelAll(e)};return e}(s);var c=function(t){return Promise.resolve(t).then(a)};function a(t){try{return t.run()}catch(e){return t.error(e)}}var h=function(t){function e(e,n){var r=this;t.call(this);this.timer=e;this.timeline=n;this._timer=null;this._nextArrival=Infinity;this._runReadyTasksBound=function(){return r._runReadyTasks(r.now())}}if(t)e.__proto__=t;e.prototype=Object.create(t&&t.prototype);e.prototype.constructor=e;e.prototype.now=function t(){return this.timer.now()};e.prototype.scheduleTask=function t(e,n,r,i){var s=this.now()+Math.max(0,n);var u=new o(s,e,r,i,this);this.timeline.add(u);this._scheduleNextRun();return u};e.prototype.relative=function t(e){return new u(e,this)};e.prototype.cancel=function t(e){e.active=false;if(this.timeline.remove(e)){this._reschedule()}};e.prototype.cancelAll=function t(e){this.timeline.removeAll(e);this._reschedule()};e.prototype._reschedule=function t(){if(this.timeline.isEmpty()){this._unschedule()}else{this._scheduleNextRun(this.now())}};e.prototype._unschedule=function t(){this.timer.clearTimer(this._timer);this._timer=null};e.prototype._scheduleNextRun=function t(){if(this.timeline.isEmpty()){return}var e=this.timeline.nextArrival();if(this._timer===null){this._scheduleNextArrival(e)}else if(e<this._nextArrival){this._unschedule();this._scheduleNextArrival(e)}};e.prototype._scheduleNextArrival=function t(e){this._nextArrival=e;var n=Math.max(0,e-this.now());this._timer=this.timer.setTimer(this._runReadyTasksBound,n)};e.prototype._runReadyTasks=function t(){this._timer=null;this.timeline.runTasks(this.now(),a);this._scheduleNextRun()};return e}(s);var f=function t(){this.tasks=[]};f.prototype.nextArrival=function t(){return this.isEmpty()?Infinity:this.tasks[0].time};f.prototype.isEmpty=function t(){return this.tasks.length===0};f.prototype.add=function t(e){p(e,this.tasks)};f.prototype.remove=function t(e){var r=w(y(e),this.tasks);if(r>=0&&r<this.tasks.length){var i=n(e,this.tasks[r].events);if(i>=0){this.tasks[r].events.splice(i,1);return true}}return false};f.prototype.removeAll=function t(e){var n=this;for(var r=0;r<this.tasks.length;++r){k(e,n.tasks[r])}};f.prototype.runTasks=function t(e,n){var r=this;var i=this.tasks;var o=i.length;var s=0;while(s<o&&i[s].time<=e){++s}this.tasks=i.slice(s);for(var u=0;u<s;++u){r.tasks=l(n,i[u].events,r.tasks)}};function l(t,e,n){for(var r=0;r<e.length;++r){var i=e[r];if(i.active){t(i);if(i.period>=0&&i.active){i.time=i.time+i.period;p(i,n)}}}return n}function p(t,e){var n=e.length;var r=y(t);if(n===0){e.push(_(r,[t]));return}var i=w(r,e);if(i>=n){e.push(_(r,[t]))}else{v(t,e,r,i)}}function v(t,e,n,r){var i=e[r];if(n===i.time){m(t,i.events,n)}else{e.splice(r,0,_(n,[t]))}}function m(t,e){if(e.length===0||t.time>=e[e.length-1].time){e.push(t)}else{d(t,e)}}function d(t,e){for(var n=0;n<e.length;n++){if(t.time<e[n].time){e.splice(n,0,t);break}}}function y(t){return Math.floor(t.time)}function k(t,n){n.events=e(t,n.events)}function w(t,e){var n=0;var r=e.length;var i,o;while(n<r){i=Math.floor((n+r)/2);o=e[i];if(t===o.time){return i}else if(t<o.time){r=i}else{n=i+1}}return r}var _=function(t,e){return{time:t,events:e}};var T=function t(e){this._clock=e};T.prototype.now=function t(){return this._clock.now()};T.prototype.setTimer=function t(e,n){return n<=0?x(e):setTimeout(e,n)};T.prototype.clearTimer=function t(e){return e instanceof g?e.cancel():clearTimeout(e)};var g=function t(e){this.f=e;this.active=true};g.prototype.run=function t(){return this.active&&this.f()};g.prototype.error=function t(e){throw e};g.prototype.cancel=function t(){this.active=false};function x(t){var e=new g(t);c(e);return e}var A=function t(e,n){this.origin=n;this.clock=e};A.prototype.now=function t(){return this.clock.now()-this.origin};var R=function t(e,n){this.origin=n;this.hrtime=e};R.prototype.now=function t(){var e=this.hrtime(this.origin);return(e[0]*1e9+e[1])/1e6};var C=function(t){return new A(t,t.now())};var N=function(){return C(performance)};var O=function(){return C(Date)};var b=function(){return new R(process.hrtime,process.hrtime())};var M=function(){if(typeof performance!=="undefined"&&typeof performance.now==="function"){return N()}else if(typeof process!=="undefined"&&typeof process.hrtime==="function"){return b()}return O()};var j=r(function(t,e){return e.asap(t)});var D=i(function(t,e,n){return n.delay(t,e)});var E=i(function(t,e,n){return n.periodic(t,e)});var P=r(function(t,e){return new u(t,e)});var B=r(function(t,e){return new h(t,e)});var H=function(){return new h(I(),new f)};var I=function(){return new T(M())};var S=function(t){return new T(t)};var q=function(){return new f};t.newScheduler=B;t.newDefaultScheduler=H;t.newDefaultTimer=I;t.newClockTimer=S;t.newTimeline=q;t.RelativeClock=A;t.HRTimeClock=R;t.clockRelativeTo=C;t.newPerformanceClock=N;t.newDateClock=O;t.newHRTimeClock=b;t.newPlatformClock=M;t.asap=j;t.delay=D;t.periodic=E;t.schedulerRelativeTo=P;Object.defineProperty(t,"__esModule",{value:true})}); |
{ | ||
"name": "@most/scheduler", | ||
"version": "0.7.1", | ||
"version": "0.8.0", | ||
"description": "Reactive programming with lean, functions-only, curried, tree-shakeable API", | ||
@@ -59,4 +59,4 @@ "typings": "type-definitions/index.d.ts", | ||
"@most/prelude": "^1.5.2", | ||
"@most/types": "^0.5.0" | ||
"@most/types": "^0.8.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { Scheduler, Timeline, Timer, Time } from '@most/types'; | ||
import { Scheduler, Task, ScheduledTask, Timeline, Timer, Time, Delay, Period, Offset } from '@most/types'; | ||
@@ -12,2 +12,5 @@ export type Clock = { | ||
export function schedulerRelativeTo (offset: Offset, scheduler: Scheduler): Scheduler | ||
export function schedulerRelativeTo (offset: Offset): (scheduler: Scheduler) => Scheduler | ||
export function newClockTimer (clock: Clock): Timer; | ||
@@ -20,2 +23,16 @@ export function newTimeline (): Timeline; | ||
export function newHRTimeClock (): Clock; | ||
export function clockRelativeTo (clock: Clock): Clock; | ||
export function asap (task: Task, scheduler: Scheduler): ScheduledTask; | ||
export function asap (task: Task): (scheduler: Scheduler) => ScheduledTask; | ||
export function delay (delay: Delay, task: Task, scheduler: Scheduler): ScheduledTask; | ||
export function delay (delay: Delay): (task: Task, scheduler: Scheduler) => ScheduledTask; | ||
export function delay (delay: Delay, task: Task): (scheduler: Scheduler) => ScheduledTask; | ||
export function delay (delay: Delay): (task: Task) => (scheduler: Scheduler) => ScheduledTask; | ||
export function periodic (period: Period, task: Task, scheduler: Scheduler): ScheduledTask; | ||
export function periodic (period: Period): (task: Task, scheduler: Scheduler) => ScheduledTask; | ||
export function periodic (period: Period, task: Task): (scheduler: Scheduler) => ScheduledTask; | ||
export function periodic (period: Period): (task: Task) => (scheduler: Scheduler) => ScheduledTask; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
103544
838
+ Added@most/types@0.8.0(transitive)
- Removed@most/types@0.5.0(transitive)
Updated@most/types@^0.8.0