(task: ITask<T>, delay: number = this.defaultDelay)
| 25 | } |
| 26 | |
| 27 | public trigger(task: ITask<T>, delay: number = this.defaultDelay): Promise<T> { |
| 28 | this.task = task; |
| 29 | if (delay >= 0) { |
| 30 | this.cancelTimeout(); |
| 31 | } |
| 32 | |
| 33 | if (!this.completionPromise) { |
| 34 | this.completionPromise = new Promise<T>((resolve) => { |
| 35 | this.onSuccess = resolve |
| 36 | }).then(() => { |
| 37 | this.completionPromise = undefined; |
| 38 | this.onSuccess = undefined; |
| 39 | var result = this.task!(); |
| 40 | this.task = undefined; |
| 41 | return result; |
| 42 | }); |
| 43 | } |
| 44 | |
| 45 | if (delay >= 0 || this.timeout === void 0) { |
| 46 | this.timeout = setTimeout(() => { |
| 47 | this.timeout = undefined; |
| 48 | this.onSuccess!(undefined); |
| 49 | }, delay >= 0 ? delay : this.defaultDelay); |
| 50 | } |
| 51 | |
| 52 | return this.completionPromise; |
| 53 | } |
| 54 | |
| 55 | public forceDelivery(): T | undefined { |
| 56 | if (!this.completionPromise) { |
no test coverage detected