UNPKG

chargebee-typescript

Version:

A library in typescript for integrating with Chargebee.

32 lines (31 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProcessWait = void 0; const util_1 = require("./util"); class ProcessWait { constructor(handler, envArgs) { if (typeof handler == 'undefined' || !util_1.Util.isFunction(handler)) { throw new Error('The handling parameter should be a method.'); } this.handler = handler; util_1.Util.extend(true, this._env, envArgs); } request(callBack, envOptions) { let jsonConstructor = {}.constructor; if (typeof envOptions !== 'undefined') { util_1.Util.extend(true, this._env, envOptions); } else if (typeof callBack !== 'undefined' && callBack.constructor === jsonConstructor && !util_1.Util.isFunction(callBack)) { util_1.Util.extend(true, this._env, callBack); callBack = undefined; } if (typeof callBack !== 'undefined' && !util_1.Util.isFunction(callBack)) { throw new Error('The callback parameter passed is incorrect.'); } let deferred = util_1.Util.createDeferred(callBack); let _self = this; this.handler(deferred, _self); return deferred.promise; } } exports.ProcessWait = ProcessWait;