コード例 #1
0
ファイル: TimeLine.js プロジェクト: wavesplatform/WavesGUI
 /**
  * @param {function} callback
  * @param {number} timeout
  * @return {PromiseControl}
  */
 timeout(callback, timeout) {
     const start = Date.now();
     const id = tsUtils.uniqueId('timeLineItem');
     const defer = $.Deferred();
     const promise = new PromiseControl(defer.promise());
     promise.id = id;
     promise.start = start;
     promise.time = timeout;
     this._listeners.add({
         handler: callback,
         timeout,
         start,
         id,
         defer
     });
     if (this._listeners.list.length === 1) {
         this._addTimeout();
     }
     return promise;
 }
コード例 #2
0
                return new Promise((resolve) => {
                    const id = tsUtils.uniqueId('cmd__');
                    const params = { id, data, referer: this._sessionId };
                    const command = this._getCommandKey(targetSessionId, apiMethod);

                    this._messageHash[id] = (result) => {
                        delete this._messageHash[id];
                        this._clearCommand(command);
                        resolve(result);
                    };

                    this._dispatch(command, params);

                    setTimeout(() => {
                        if (this._messageHash[id]) {
                            this._messageHash[id]({
                                status: 'error',
                                message: new Error('Timeout limit error!')
                            });
                        }
                    }, 1000);
                });
コード例 #3
0
            /**
             * @param {string} type
             * @param {INotificationObj} notificationObj
             * @param {number} [delay]
             * @return {Promise}
             * @private
             */
            _push(type, notificationObj, delay = this._options.defaultDelay) {
                const defer = $q.defer();
                const promise = defer.promise;
                notificationObj.id = notificationObj.id || tsUtils.uniqueId('n');

                /**
                 * @type {_INotificationItem}
                 */
                const notification = utils.liteObject({
                    id: notificationObj.id,
                    defer,
                    promise,
                    notificationObj,
                    delay,
                    type,
                    $element: null,
                    destroy: null
                });

                this._queue.push(notification);

                return promise;
            }