export class Task { public static Yield(): Promise { return new Promise((resolve) => { setTimeout(resolve, 0); }); } public static Delay(milliseconds: number): Promise { return new Promise((resolve) => { setTimeout(resolve, milliseconds); }); } private promise: Promise; private resolveMethod: (result: T) => void; private rejectMethod: (error: E) => void; constructor() { this.promise = new Promise( (resolve: (result: T) => void, reject: (error: E) => void) => { this.resolveMethod = resolve; this.rejectMethod = reject; }, ); } public resolve(value: T): void { this.resolveMethod(value); } public reject(error: E): void { this.rejectMethod(error); } public getResultAsync(): Promise { return this.promise; } }