Something went wrong on our end
Select Git revision
processing.js
-
Volker Schukai authoredVolker Schukai authored
processing.js 5.04 KiB
'use strict';
/**
* @author schukai GmbH
*/
import {internalSymbol} from "../constants.js";
import {assignToNamespace, Monster} from '../namespace.js';
import {Base} from "../types/base.js";
import {getGlobalFunction} from "../types/global.js";
import {isFunction, isInteger} from "../types/is.js";
import {Queue} from "../types/queue.js";
import {validateFunction, validateInteger} from "../types/validate.js";
/**
* @private
*/
class Callback {
/**
*
* @param {function} callback
* @param {int|undefined} time
* @throws {TypeError} value is not a function
* @throws {TypeError} value is not an integer
* @private
*/
constructor(callback, time) {
this[internalSymbol] = {
callback: validateFunction(callback),
time: validateInteger(time ?? 0)
};
}
/**
* @private
* @param {*} data
* @return {Promise}
*/
run(data) {
const self = this;
return new Promise((resolve, reject) => {
getGlobalFunction('setTimeout')(() => {
try {
resolve(self[internalSymbol].callback(data));
} catch (e) {
reject(e);
}
},
self[internalSymbol].time);
})
}
}
/**
* This class allows to execute several functions in order.
*
* Functions and timeouts can be passed. If a timeout is passed, it applies to all further functions.
* In the example
*
* `timeout1, function1, function2, function3, timeout2, function4`
*
* the timeout1 is valid for the functions 1, 2 and 3 and the timeout2 for the function4.