@most/scheduler
Advanced tools
Comparing version 0.12.0 to 0.13.0
@@ -85,59 +85,27 @@ /** @license MIT License (c) copyright 2010-2016 original author or authors */ | ||
// 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 () {}; | ||
var RelativeScheduler = function RelativeScheduler (origin, scheduler) { | ||
this.origin = origin; | ||
this.scheduler = scheduler; | ||
}; | ||
AbstractScheduler.prototype.asap = function asap (task) { | ||
return this.scheduleTask(0, 0, -1, task) | ||
RelativeScheduler.prototype.currentTime = function currentTime () { | ||
return this.scheduler.currentTime() - this.origin | ||
}; | ||
AbstractScheduler.prototype.delay = function delay (delay$1, task) { | ||
return this.scheduleTask(0, delay$1, -1, task) | ||
RelativeScheduler.prototype.scheduleTask = function scheduleTask (localOffset, delay, period, task) { | ||
return this.scheduler.scheduleTask(localOffset + this.origin, delay, period, task) | ||
}; | ||
AbstractScheduler.prototype.periodic = function periodic (period, task) { | ||
return this.scheduleTask(0, 0, period, task) | ||
RelativeScheduler.prototype.relative = function relative (origin) { | ||
return new RelativeScheduler(origin + this.origin, this.scheduler) | ||
}; | ||
AbstractScheduler.prototype.schedule = function schedule (delay, period, task) { | ||
return this.scheduleTask(0, delay, period, task) | ||
RelativeScheduler.prototype.cancel = function cancel (task) { | ||
return this.scheduler.cancel(task) | ||
}; | ||
var RelativeScheduler = (function (AbstractScheduler$$1) { | ||
function RelativeScheduler (origin, scheduler) { | ||
AbstractScheduler$$1.call(this); | ||
this.origin = origin; | ||
this.scheduler = scheduler; | ||
} | ||
RelativeScheduler.prototype.cancelAll = function cancelAll (f) { | ||
return this.scheduler.cancelAll(f) | ||
}; | ||
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 */ | ||
@@ -157,91 +125,82 @@ | ||
var Scheduler = (function (AbstractScheduler$$1) { | ||
function Scheduler (timer, timeline) { | ||
var this$1 = this; | ||
var Scheduler = function Scheduler (timer, timeline) { | ||
var this$1 = this; | ||
AbstractScheduler$$1.call(this); | ||
this.timer = timer; | ||
this.timeline = timeline; | ||
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.currentTime()); }; | ||
}; | ||
if ( AbstractScheduler$$1 ) Scheduler.__proto__ = AbstractScheduler$$1; | ||
Scheduler.prototype = Object.create( AbstractScheduler$$1 && AbstractScheduler$$1.prototype ); | ||
Scheduler.prototype.constructor = Scheduler; | ||
Scheduler.prototype.currentTime = function currentTime () { | ||
return this.timer.now() | ||
}; | ||
Scheduler.prototype.now = function now () { | ||
return this.timer.now() | ||
}; | ||
Scheduler.prototype.scheduleTask = function scheduleTask (localOffset, delay, period, task) { | ||
var time = this.currentTime() + Math.max(0, delay); | ||
var st = new ScheduledTask(time, localOffset, period, task, this); | ||
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); | ||
this.timeline.add(st); | ||
this._scheduleNextRun(); | ||
return st | ||
}; | ||
this.timeline.add(st); | ||
this._scheduleNextRun(); | ||
return st | ||
}; | ||
Scheduler.prototype.relative = function relative (offset) { | ||
return new RelativeScheduler(offset, this) | ||
}; | ||
Scheduler.prototype.relative = function relative (offset) { | ||
return new RelativeScheduler(offset, this) | ||
}; | ||
Scheduler.prototype.cancel = function cancel (task) { | ||
task.active = false; | ||
if (this.timeline.remove(task)) { | ||
this._reschedule(); | ||
} | ||
}; | ||
Scheduler.prototype.cancelAll = function cancelAll (f) { | ||
this.timeline.removeAll(f); | ||
Scheduler.prototype.cancel = function cancel (task) { | ||
task.active = false; | ||
if (this.timeline.remove(task)) { | ||
this._reschedule(); | ||
}; | ||
} | ||
}; | ||
Scheduler.prototype._reschedule = function _reschedule () { | ||
if (this.timeline.isEmpty()) { | ||
this._unschedule(); | ||
} else { | ||
this._scheduleNextRun(this.now()); | ||
} | ||
}; | ||
Scheduler.prototype.cancelAll = function cancelAll (f) { | ||
this.timeline.removeAll(f); | ||
this._reschedule(); | ||
}; | ||
Scheduler.prototype._unschedule = function _unschedule () { | ||
this.timer.clearTimer(this._timer); | ||
this._timer = null; | ||
}; | ||
Scheduler.prototype._reschedule = function _reschedule () { | ||
if (this.timeline.isEmpty()) { | ||
this._unschedule(); | ||
} else { | ||
this._scheduleNextRun(this.currentTime()); | ||
} | ||
}; | ||
Scheduler.prototype._scheduleNextRun = function _scheduleNextRun () { // eslint-disable-line complexity | ||
if (this.timeline.isEmpty()) { | ||
return | ||
} | ||
Scheduler.prototype._unschedule = function _unschedule () { | ||
this.timer.clearTimer(this._timer); | ||
this._timer = null; | ||
}; | ||
var nextArrival = this.timeline.nextArrival(); | ||
Scheduler.prototype._scheduleNextRun = function _scheduleNextRun () { // eslint-disable-line complexity | ||
if (this.timeline.isEmpty()) { | ||
return | ||
} | ||
if (this._timer === null) { | ||
this._scheduleNextArrival(nextArrival); | ||
} else if (nextArrival < this._nextArrival) { | ||
this._unschedule(); | ||
this._scheduleNextArrival(nextArrival); | ||
} | ||
}; | ||
var nextArrival = this.timeline.nextArrival(); | ||
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); | ||
}; | ||
if (this._timer === null) { | ||
this._scheduleNextArrival(nextArrival); | ||
} else if (nextArrival < this._nextArrival) { | ||
this._unschedule(); | ||
this._scheduleNextArrival(nextArrival); | ||
} | ||
}; | ||
Scheduler.prototype._runReadyTasks = function _runReadyTasks () { | ||
this._timer = null; | ||
this.timeline.runTasks(this.now(), runTask); | ||
this._scheduleNextRun(); | ||
}; | ||
Scheduler.prototype._scheduleNextArrival = function _scheduleNextArrival (nextArrival) { | ||
this._nextArrival = nextArrival; | ||
var delay = Math.max(0, nextArrival - this.currentTime()); | ||
this._timer = this.timer.setTimer(this._runReadyTasksBound, delay); | ||
}; | ||
return Scheduler; | ||
}(AbstractScheduler)); | ||
Scheduler.prototype._runReadyTasks = function _runReadyTasks () { | ||
this._timer = null; | ||
this.timeline.runTasks(this.currentTime(), runTask); | ||
this._scheduleNextRun(); | ||
}; | ||
@@ -402,3 +361,3 @@ /** @license MIT License (c) copyright 2010-2017 original author or authors */ | ||
/*global setTimeout, clearTimeout*/ | ||
/* global setTimeout, clearTimeout */ | ||
@@ -446,3 +405,3 @@ var ClockTimer = function ClockTimer (clock) { | ||
/*global performance, process*/ | ||
/* global performance, process */ | ||
@@ -486,12 +445,15 @@ var RelativeClock = function RelativeClock (clock, origin) { | ||
// Read the current time from the provided Scheduler | ||
var currentTime = function (scheduler) { return scheduler.currentTime(); }; | ||
// 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); }); | ||
var asap = curry2(function (task, scheduler) { return scheduler.scheduleTask(0, 0, -1, task); }); | ||
// Schedule a task to run after a millisecond delay | ||
var delay = curry3(function (delay, task, scheduler) { return scheduler.delay(delay, task); }); | ||
var delay = curry3(function (delay, task, scheduler) { return scheduler.scheduleTask(0, delay, -1, 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 periodic = curry3(function (period, task, scheduler) { return scheduler.scheduleTask(0, 0, period, task); }); | ||
@@ -518,3 +480,3 @@ // Cancel a scheduledTask | ||
export { newScheduler, newDefaultScheduler, newDefaultTimer, newClockTimer, newTimeline, RelativeClock, HRTimeClock, clockRelativeTo, newPerformanceClock, newDateClock, newHRTimeClock, newPlatformClock, asap, delay, periodic, cancelTask, cancelAllTasks, schedulerRelativeTo }; | ||
export { newScheduler, newDefaultScheduler, newDefaultTimer, newClockTimer, newTimeline, RelativeClock, HRTimeClock, clockRelativeTo, newPerformanceClock, newDateClock, newHRTimeClock, newPlatformClock, currentTime, asap, delay, periodic, cancelTask, cancelAllTasks, schedulerRelativeTo }; | ||
//# sourceMappingURL=index.es.js.map |
@@ -91,59 +91,27 @@ (function (global, factory) { | ||
// 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 () {}; | ||
var RelativeScheduler = function RelativeScheduler (origin, scheduler) { | ||
this.origin = origin; | ||
this.scheduler = scheduler; | ||
}; | ||
AbstractScheduler.prototype.asap = function asap (task) { | ||
return this.scheduleTask(0, 0, -1, task) | ||
RelativeScheduler.prototype.currentTime = function currentTime () { | ||
return this.scheduler.currentTime() - this.origin | ||
}; | ||
AbstractScheduler.prototype.delay = function delay (delay$1, task) { | ||
return this.scheduleTask(0, delay$1, -1, task) | ||
RelativeScheduler.prototype.scheduleTask = function scheduleTask (localOffset, delay, period, task) { | ||
return this.scheduler.scheduleTask(localOffset + this.origin, delay, period, task) | ||
}; | ||
AbstractScheduler.prototype.periodic = function periodic (period, task) { | ||
return this.scheduleTask(0, 0, period, task) | ||
RelativeScheduler.prototype.relative = function relative (origin) { | ||
return new RelativeScheduler(origin + this.origin, this.scheduler) | ||
}; | ||
AbstractScheduler.prototype.schedule = function schedule (delay, period, task) { | ||
return this.scheduleTask(0, delay, period, task) | ||
RelativeScheduler.prototype.cancel = function cancel (task) { | ||
return this.scheduler.cancel(task) | ||
}; | ||
var RelativeScheduler = (function (AbstractScheduler$$1) { | ||
function RelativeScheduler (origin, scheduler) { | ||
AbstractScheduler$$1.call(this); | ||
this.origin = origin; | ||
this.scheduler = scheduler; | ||
} | ||
RelativeScheduler.prototype.cancelAll = function cancelAll (f) { | ||
return this.scheduler.cancelAll(f) | ||
}; | ||
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 */ | ||
@@ -163,91 +131,82 @@ | ||
var Scheduler = (function (AbstractScheduler$$1) { | ||
function Scheduler (timer, timeline) { | ||
var this$1 = this; | ||
var Scheduler = function Scheduler (timer, timeline) { | ||
var this$1 = this; | ||
AbstractScheduler$$1.call(this); | ||
this.timer = timer; | ||
this.timeline = timeline; | ||
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.currentTime()); }; | ||
}; | ||
if ( AbstractScheduler$$1 ) Scheduler.__proto__ = AbstractScheduler$$1; | ||
Scheduler.prototype = Object.create( AbstractScheduler$$1 && AbstractScheduler$$1.prototype ); | ||
Scheduler.prototype.constructor = Scheduler; | ||
Scheduler.prototype.currentTime = function currentTime () { | ||
return this.timer.now() | ||
}; | ||
Scheduler.prototype.now = function now () { | ||
return this.timer.now() | ||
}; | ||
Scheduler.prototype.scheduleTask = function scheduleTask (localOffset, delay, period, task) { | ||
var time = this.currentTime() + Math.max(0, delay); | ||
var st = new ScheduledTask(time, localOffset, period, task, this); | ||
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); | ||
this.timeline.add(st); | ||
this._scheduleNextRun(); | ||
return st | ||
}; | ||
this.timeline.add(st); | ||
this._scheduleNextRun(); | ||
return st | ||
}; | ||
Scheduler.prototype.relative = function relative (offset) { | ||
return new RelativeScheduler(offset, this) | ||
}; | ||
Scheduler.prototype.relative = function relative (offset) { | ||
return new RelativeScheduler(offset, this) | ||
}; | ||
Scheduler.prototype.cancel = function cancel (task) { | ||
task.active = false; | ||
if (this.timeline.remove(task)) { | ||
this._reschedule(); | ||
} | ||
}; | ||
Scheduler.prototype.cancelAll = function cancelAll (f) { | ||
this.timeline.removeAll(f); | ||
Scheduler.prototype.cancel = function cancel (task) { | ||
task.active = false; | ||
if (this.timeline.remove(task)) { | ||
this._reschedule(); | ||
}; | ||
} | ||
}; | ||
Scheduler.prototype._reschedule = function _reschedule () { | ||
if (this.timeline.isEmpty()) { | ||
this._unschedule(); | ||
} else { | ||
this._scheduleNextRun(this.now()); | ||
} | ||
}; | ||
Scheduler.prototype.cancelAll = function cancelAll (f) { | ||
this.timeline.removeAll(f); | ||
this._reschedule(); | ||
}; | ||
Scheduler.prototype._unschedule = function _unschedule () { | ||
this.timer.clearTimer(this._timer); | ||
this._timer = null; | ||
}; | ||
Scheduler.prototype._reschedule = function _reschedule () { | ||
if (this.timeline.isEmpty()) { | ||
this._unschedule(); | ||
} else { | ||
this._scheduleNextRun(this.currentTime()); | ||
} | ||
}; | ||
Scheduler.prototype._scheduleNextRun = function _scheduleNextRun () { // eslint-disable-line complexity | ||
if (this.timeline.isEmpty()) { | ||
return | ||
} | ||
Scheduler.prototype._unschedule = function _unschedule () { | ||
this.timer.clearTimer(this._timer); | ||
this._timer = null; | ||
}; | ||
var nextArrival = this.timeline.nextArrival(); | ||
Scheduler.prototype._scheduleNextRun = function _scheduleNextRun () { // eslint-disable-line complexity | ||
if (this.timeline.isEmpty()) { | ||
return | ||
} | ||
if (this._timer === null) { | ||
this._scheduleNextArrival(nextArrival); | ||
} else if (nextArrival < this._nextArrival) { | ||
this._unschedule(); | ||
this._scheduleNextArrival(nextArrival); | ||
} | ||
}; | ||
var nextArrival = this.timeline.nextArrival(); | ||
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); | ||
}; | ||
if (this._timer === null) { | ||
this._scheduleNextArrival(nextArrival); | ||
} else if (nextArrival < this._nextArrival) { | ||
this._unschedule(); | ||
this._scheduleNextArrival(nextArrival); | ||
} | ||
}; | ||
Scheduler.prototype._runReadyTasks = function _runReadyTasks () { | ||
this._timer = null; | ||
this.timeline.runTasks(this.now(), runTask); | ||
this._scheduleNextRun(); | ||
}; | ||
Scheduler.prototype._scheduleNextArrival = function _scheduleNextArrival (nextArrival) { | ||
this._nextArrival = nextArrival; | ||
var delay = Math.max(0, nextArrival - this.currentTime()); | ||
this._timer = this.timer.setTimer(this._runReadyTasksBound, delay); | ||
}; | ||
return Scheduler; | ||
}(AbstractScheduler)); | ||
Scheduler.prototype._runReadyTasks = function _runReadyTasks () { | ||
this._timer = null; | ||
this.timeline.runTasks(this.currentTime(), runTask); | ||
this._scheduleNextRun(); | ||
}; | ||
@@ -408,3 +367,3 @@ /** @license MIT License (c) copyright 2010-2017 original author or authors */ | ||
/*global setTimeout, clearTimeout*/ | ||
/* global setTimeout, clearTimeout */ | ||
@@ -452,3 +411,3 @@ var ClockTimer = function ClockTimer (clock) { | ||
/*global performance, process*/ | ||
/* global performance, process */ | ||
@@ -492,12 +451,15 @@ var RelativeClock = function RelativeClock (clock, origin) { | ||
// Read the current time from the provided Scheduler | ||
var currentTime = function (scheduler) { return scheduler.currentTime(); }; | ||
// 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); }); | ||
var asap = curry2(function (task, scheduler) { return scheduler.scheduleTask(0, 0, -1, task); }); | ||
// Schedule a task to run after a millisecond delay | ||
var delay = curry3(function (delay, task, scheduler) { return scheduler.delay(delay, task); }); | ||
var delay = curry3(function (delay, task, scheduler) { return scheduler.scheduleTask(0, delay, -1, 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 periodic = curry3(function (period, task, scheduler) { return scheduler.scheduleTask(0, 0, period, task); }); | ||
@@ -536,2 +498,3 @@ // Cancel a scheduledTask | ||
exports.newPlatformClock = newPlatformClock; | ||
exports.currentTime = currentTime; | ||
exports.asap = asap; | ||
@@ -538,0 +501,0 @@ exports.delay = delay; |
@@ -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=void 0,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 l=function t(){this.tasks=[]};l.prototype.nextArrival=function t(){return this.isEmpty()?Infinity:this.tasks[0].time};l.prototype.isEmpty=function t(){return this.tasks.length===0};l.prototype.add=function t(e){p(e,this.tasks)};l.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};l.prototype.removeAll=function t(e){var n=this;for(var r=0;r<this.tasks.length;++r){k(e,n.tasks[r])}};l.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=f(n,i[u].events,r.tasks)}};function f(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){d(t,i.events,n)}else{e.splice(r,0,_(n,[t]))}}function d(t,e){if(e.length===0||t.time>=e[e.length-1].time){e.push(t)}else{m(t,e)}}function m(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=function(t){return t.dispose()};var B=r(function(t,e){return e.cancelAll(t)});var H=r(function(t,e){return new u(t,e)});var I=r(function(t,e){return new h(t,e)});var S=function(){return new h(q(),new l)};var q=function(){return new T(M())};var z=function(t){return new T(t)};var F=function(){return new l};t.newScheduler=I;t.newDefaultScheduler=S;t.newDefaultTimer=q;t.newClockTimer=z;t.newTimeline=F;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.cancelTask=P;t.cancelAllTasks=B;t.schedulerRelativeTo=H;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 r=e.length;var n=new Array(r);var i=0;for(var s=void 0,o=0;o<r;++o){s=e[o];if(!t(s)){n[i]=s;++i}}n.length=i;return n}function r(t,e){for(var r=0,n=e.length;r<n;++r){if(t===e[r]){return r}}return-1}function n(t){function e(r,n){switch(arguments.length){case 0:return e;case 1:return function(e){return t(r,e)};default:return t(r,n)}}return e}function i(t){function e(r,i,s){switch(arguments.length){case 0:return e;case 1:return n(function(e,n){return t(r,e,n)});case 2:return function(e){return t(r,i,e)};default:return t(r,i,s)}}return e}var s=function t(e,r,n,i,s){this.time=e;this.localOffset=r;this.period=n;this.task=i;this.scheduler=s;this.active=true};s.prototype.run=function t(){return this.task.run(this.time-this.localOffset)};s.prototype.error=function t(e){return this.task.error(this.time-this.localOffset,e)};s.prototype.dispose=function t(){this.scheduler.cancel(this);return this.task.dispose()};var o=function t(e,r){this.origin=e;this.scheduler=r};o.prototype.currentTime=function t(){return this.scheduler.currentTime()-this.origin};o.prototype.scheduleTask=function t(e,r,n,i){return this.scheduler.scheduleTask(e+this.origin,r,n,i)};o.prototype.relative=function t(e){return new o(e+this.origin,this.scheduler)};o.prototype.cancel=function t(e){return this.scheduler.cancel(e)};o.prototype.cancelAll=function t(e){return this.scheduler.cancelAll(e)};var u=function(t){return Promise.resolve(t).then(c)};function c(t){try{return t.run()}catch(e){return t.error(e)}}var a=function t(e,r){var n=this;this.timer=e;this.timeline=r;this._timer=null;this._nextArrival=Infinity;this._runReadyTasksBound=function(){return n._runReadyTasks(n.currentTime())}};a.prototype.currentTime=function t(){return this.timer.now()};a.prototype.scheduleTask=function t(e,r,n,i){var o=this.currentTime()+Math.max(0,r);var u=new s(o,e,n,i,this);this.timeline.add(u);this._scheduleNextRun();return u};a.prototype.relative=function t(e){return new o(e,this)};a.prototype.cancel=function t(e){e.active=false;if(this.timeline.remove(e)){this._reschedule()}};a.prototype.cancelAll=function t(e){this.timeline.removeAll(e);this._reschedule()};a.prototype._reschedule=function t(){if(this.timeline.isEmpty()){this._unschedule()}else{this._scheduleNextRun(this.currentTime())}};a.prototype._unschedule=function t(){this.timer.clearTimer(this._timer);this._timer=null};a.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)}};a.prototype._scheduleNextArrival=function t(e){this._nextArrival=e;var r=Math.max(0,e-this.currentTime());this._timer=this.timer.setTimer(this._runReadyTasksBound,r)};a.prototype._runReadyTasks=function t(){this._timer=null;this.timeline.runTasks(this.currentTime(),c);this._scheduleNextRun()};var h=function t(){this.tasks=[]};h.prototype.nextArrival=function t(){return this.isEmpty()?Infinity:this.tasks[0].time};h.prototype.isEmpty=function t(){return this.tasks.length===0};h.prototype.add=function t(e){f(e,this.tasks)};h.prototype.remove=function t(e){var n=k(d(e),this.tasks);if(n>=0&&n<this.tasks.length){var i=r(e,this.tasks[n].events);if(i>=0){this.tasks[n].events.splice(i,1);return true}}return false};h.prototype.removeAll=function t(e){var r=this;for(var n=0;n<this.tasks.length;++n){y(e,r.tasks[n])}};h.prototype.runTasks=function t(e,r){var n=this;var i=this.tasks;var s=i.length;var o=0;while(o<s&&i[o].time<=e){++o}this.tasks=i.slice(o);for(var u=0;u<o;++u){n.tasks=l(r,i[u].events,n.tasks)}};function l(t,e,r){for(var n=0;n<e.length;++n){var i=e[n];if(i.active){t(i);if(i.period>=0&&i.active){i.time=i.time+i.period;f(i,r)}}}return r}function f(t,e){var r=e.length;var n=d(t);if(r===0){e.push(T(n,[t]));return}var i=k(n,e);if(i>=r){e.push(T(n,[t]))}else{p(t,e,n,i)}}function p(t,e,r,n){var i=e[n];if(r===i.time){v(t,i.events,r)}else{e.splice(n,0,T(r,[t]))}}function v(t,e){if(e.length===0||t.time>=e[e.length-1].time){e.push(t)}else{m(t,e)}}function m(t,e){for(var r=0;r<e.length;r++){if(t.time<e[r].time){e.splice(r,0,t);break}}}function d(t){return Math.floor(t.time)}function y(t,r){r.events=e(t,r.events)}function k(t,e){var r=0;var n=e.length;var i,s;while(r<n){i=Math.floor((r+n)/2);s=e[i];if(t===s.time){return i}else if(t<s.time){n=i}else{r=i+1}}return n}var T=function(t,e){return{time:t,events:e}};var w=function t(e){this._clock=e};w.prototype.now=function t(){return this._clock.now()};w.prototype.setTimer=function t(e,r){return r<=0?g(e):setTimeout(e,r)};w.prototype.clearTimer=function t(e){return e instanceof _?e.cancel():clearTimeout(e)};var _=function t(e){this.f=e;this.active=true};_.prototype.run=function t(){return this.active&&this.f()};_.prototype.error=function t(e){throw e};_.prototype.cancel=function t(){this.active=false};function g(t){var e=new _(t);u(e);return e}var x=function t(e,r){this.origin=r;this.clock=e};x.prototype.now=function t(){return this.clock.now()-this.origin};var A=function t(e,r){this.origin=r;this.hrtime=e};A.prototype.now=function t(){var e=this.hrtime(this.origin);return(e[0]*1e9+e[1])/1e6};var R=function(t){return new x(t,t.now())};var C=function(){return R(performance)};var N=function(){return R(Date)};var M=function(){return new A(process.hrtime,process.hrtime())};var D=function(){if(typeof performance!=="undefined"&&typeof performance.now==="function"){return C()}else if(typeof process!=="undefined"&&typeof process.hrtime==="function"){return M()}return N()};var E=function(t){return t.currentTime()};var O=n(function(t,e){return e.scheduleTask(0,0,-1,t)});var P=i(function(t,e,r){return r.scheduleTask(0,t,-1,e)});var b=i(function(t,e,r){return r.scheduleTask(0,0,t,e)});var j=function(t){return t.dispose()};var B=n(function(t,e){return e.cancelAll(t)});var H=n(function(t,e){return new o(t,e)});var I=n(function(t,e){return new a(t,e)});var S=function(){return new a(q(),new h)};var q=function(){return new w(D())};var z=function(t){return new w(t)};var F=function(){return new h};t.newScheduler=I;t.newDefaultScheduler=S;t.newDefaultTimer=q;t.newClockTimer=z;t.newTimeline=F;t.RelativeClock=x;t.HRTimeClock=A;t.clockRelativeTo=R;t.newPerformanceClock=C;t.newDateClock=N;t.newHRTimeClock=M;t.newPlatformClock=D;t.currentTime=E;t.asap=O;t.delay=P;t.periodic=b;t.cancelTask=j;t.cancelAllTasks=B;t.schedulerRelativeTo=H;Object.defineProperty(t,"__esModule",{value:true})}); |
{ | ||
"name": "@most/scheduler", | ||
"version": "0.12.0", | ||
"version": "0.13.0", | ||
"description": "Reactive programming with lean, functions-only, curried, tree-shakeable API", | ||
@@ -16,3 +16,3 @@ "typings": "type-definitions/index.d.ts", | ||
"test:unit": "nyc --reporter=text-summary mocha -r buba/register --reporter dot --recursive 'test/**/*-test.js'", | ||
"test:lint": "eslint --fix --ignore-path ../../.eslintignore src test", | ||
"test:lint": "standard --fix 'src/**/*.js' 'test/**/*.js' --verbose | snazzy", | ||
"test:flow": "flow check", | ||
@@ -45,7 +45,4 @@ "build": "npm run build:dist && npm run build:min && npm run build:flow", | ||
"@briancavalier/assert": "^3.2.0", | ||
"@most/eslint-config-most": "^1.0.3", | ||
"babel-eslint": "^7.1.1", | ||
"buba": "^4.0.2", | ||
"cpy-cli": "^1.0.1", | ||
"eslint": "^3.15.0", | ||
"flow-bin": "^0.53.1", | ||
@@ -58,8 +55,16 @@ "mocha": "^3.4.2", | ||
"sinon": "^1.17.7", | ||
"snazzy": "^7.0.0", | ||
"standard": "^10.0.3", | ||
"uglify-js": "^2.7.5" | ||
}, | ||
"dependencies": { | ||
"@most/prelude": "^1.6.3", | ||
"@most/types": "^0.11.0" | ||
"@most/prelude": "^1.6.4", | ||
"@most/types": "^0.11.1" | ||
}, | ||
"standard": { | ||
"ignore": [ | ||
"test/perf", | ||
"test/flow" | ||
] | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { Scheduler, Task, ScheduledTask, Timeline, Timer, Clock, Delay, Period, Offset } from '@most/types'; | ||
import { Scheduler, Task, ScheduledTask, Timeline, Timer, Time, Clock, Delay, Period, Offset } from '@most/types'; | ||
@@ -21,2 +21,4 @@ export function newScheduler (timer: Timer, timeline: Timeline): Scheduler; | ||
export function currentTime (scheduler: Scheduler): Time | ||
export function asap (task: Task, scheduler: Scheduler): ScheduledTask; | ||
@@ -23,0 +25,0 @@ export function asap (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
13
99041
793
Updated@most/prelude@^1.6.4
Updated@most/types@^0.11.1