| 95 | } |
| 96 | |
| 97 | class DeferredImpl<T> implements Deferred<T> { |
| 98 | private _resolve!: (value: T | PromiseLike<T>) => void; |
| 99 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 100 | private _reject!: (reason?: any) => void; |
| 101 | private _resolved: boolean = false; |
| 102 | private _rejected: boolean = false; |
| 103 | private _promise: Promise<T>; |
| 104 | private _value: T | undefined; |
| 105 | public get value() { |
| 106 | return this._value; |
| 107 | } |
| 108 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 109 | constructor(private scope: any = null) { |
| 110 | // eslint-disable-next-line |
| 111 | this._promise = new Promise<T>((res, rej) => { |
| 112 | this._resolve = res; |
| 113 | this._reject = rej; |
| 114 | }); |
| 115 | } |
| 116 | public resolve(value?: T | PromiseLike<T>) { |
| 117 | this._value = value as T | undefined; |
| 118 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 119 | this._resolve.apply(this.scope ? this.scope : this, arguments as any); |
| 120 | this._resolved = true; |
| 121 | } |
| 122 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 123 | public reject(_reason?: any) { |
| 124 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 125 | this._reject.apply(this.scope ? this.scope : this, arguments as any); |
| 126 | this._rejected = true; |
| 127 | } |
| 128 | get promise(): Promise<T> { |
| 129 | return this._promise; |
| 130 | } |
| 131 | get resolved(): boolean { |
| 132 | return this._resolved; |
| 133 | } |
| 134 | get rejected(): boolean { |
| 135 | return this._rejected; |
| 136 | } |
| 137 | get completed(): boolean { |
| 138 | return this._rejected || this._resolved; |
| 139 | } |
| 140 | } |
| 141 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 142 | export function createDeferred<T>(scope: any = null): Deferred<T> { |
| 143 | return new DeferredImpl<T>(scope); |
nothing calls this directly
no outgoing calls
no test coverage detected