This repository has been archived on 2023-03-25. You can view files and clone it, but cannot push or open issues or pull requests.
mightyscape-1.1-deprecated/extensions/fablabchemnitz/papercraft/openjscad/node_modules/most/lib/scheduler/ClockTimer.js

47 lines
938 B
JavaScript

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = ClockTimer;
var _task = require('../task');
/* global setTimeout, clearTimeout */
function ClockTimer() {} /** @license MIT License (c) copyright 2010-2016 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
ClockTimer.prototype.now = Date.now;
ClockTimer.prototype.setTimer = function (f, dt) {
return dt <= 0 ? runAsap(f) : setTimeout(f, dt);
};
ClockTimer.prototype.clearTimer = function (t) {
return t instanceof Asap ? t.cancel() : clearTimeout(t);
};
function Asap(f) {
this.f = f;
this.active = true;
}
Asap.prototype.run = function () {
return this.active && this.f();
};
Asap.prototype.error = function (e) {
throw e;
};
Asap.prototype.cancel = function () {
this.active = false;
};
function runAsap(f) {
var task = new Asap(f);
(0, _task.defer)(task);
return task;
}