import {Promises} from "./promises"; import {IRetry} from "../types/types"; export class PromiseCreate { constructor(private fn: () => Promise) { } public timeout(timeout: number): this { let fn = this.fn; this.fn = () => Promises.timeout(fn(), timeout) return this } public delay(time: number): this { let fn = this.fn; this.fn = () => Promises.delay(time).then(() => fn()) return this } public retry(options: (number | IRetry) = 1): this { let fn = this.fn; this.fn = () => Promises.retry(fn, options); return this; } public run(): Promise { return this.fn(); } public runTo(): Promise<[K, T?]> { return Promises.to(this.fn()); } }