Skip to content
Snippets Groups Projects
Select Git revision
  • bff0cc2a119fc78a7ec772636c970e91a413f7db
  • master default protected
  • 1.31
  • 4.24.3
  • 4.24.2
  • 4.24.1
  • 4.24.0
  • 4.23.6
  • 4.23.5
  • 4.23.4
  • 4.23.3
  • 4.23.2
  • 4.23.1
  • 4.23.0
  • 4.22.3
  • 4.22.2
  • 4.22.1
  • 4.22.0
  • 4.21.0
  • 4.20.1
  • 4.20.0
  • 4.19.0
  • 4.18.0
23 results

script.mjs

Blame
  • 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.