![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/html/libs/absol-full/dist/js/ |
Upload File : |
/*** module: node_modules/absol-tutor/js/engine/AsyncCommand.js ***/ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.STATE_FINISH = void 0; var _OOP = _interopRequireDefault(require("absol/src/HTML5/OOP")); var _TState = _interopRequireDefault(require("./TState")); var _noop = _interopRequireDefault(require("absol/src/Code/noop")); var STATE_FINISH = 'finish'; /*** * @extends TState * @param command * @constructor */ exports.STATE_FINISH = STATE_FINISH; function StateFinish(command) { _TState.default.apply(this, arguments); } _OOP.default.mixClass(StateFinish, _TState.default); StateFinish.prototype.onStart = function () { this.command.resolve(); }; /*** * * @param {TProcess}process * @param {{}} args * @constructor */ function AsyncCommand(process, args) { this.process = process; this.args = args; this.state = null; this.promise = new Promise(function (resolve, reject) { this._resolveCb = resolve; this._rejectCb = reject; }.bind(this)); } AsyncCommand.prototype.type = 'async'; AsyncCommand.prototype.argNames = []; AsyncCommand.prototype.onStart = _noop.default; AsyncCommand.prototype.onStop = _noop.default; AsyncCommand.prototype.goto = function (state) { if (!this.state) return; // stop or not start, can not goto var clazz = this.stateClasses[state]; this.state.onStop(); this.state = new clazz(this); this.state.onStart(); }; AsyncCommand.prototype.resolve = function (result) { var stackIdx; if (this.state) { this.state.onStop(); this.onStop(); this.state = null; stackIdx = this.process.stack.indexOf(this); if (stackIdx >= 0) { this.process.stack.splice(stackIdx, 1); } else { throw new Error('Stack error: process.stack run incorrectly!'); } } if (this._resolveCb) { this._resolveCb(result); this._rejectCb = null; this._resolveCb = null; } }; AsyncCommand.prototype.reject = function (err) { if (this.state) { this.state.onStop(); this.state = null; this.onStop(); } if (this._rejectCb) { this._rejectCb(err); this._rejectCb = null; this._resolveCb = null; } }; AsyncCommand.prototype.exec = function () { if (!this.state) { this.process.stack.push(this); this.onStart(); this.state = new this.stateClasses.entry(this); this.state.onStart(); } return this.promise; }; AsyncCommand.prototype.stateClasses = {}; AsyncCommand.prototype.stateClasses.finish = StateFinish; AsyncCommand.prototype.stateClasses.entry = StateFinish; var _default = AsyncCommand; exports.default = _default;