| @@ -1,5 +1,4 | |||||
| 1 |
import { ICancellable, Constructor, IDestroyable, |
|
1 | import { ICancellable, Constructor, IDestroyable, ICancellation } from "./interfaces"; | |
| 2 | import { Cancellation } from "./Cancellation"; |
|
|||
| 3 |
|
2 | |||
| 4 | let _nextOid = 0; |
|
3 | let _nextOid = 0; | |
| 5 | const _oid = typeof Symbol === "function" ? |
|
4 | const _oid = typeof Symbol === "function" ? | |
| @@ -18,6 +17,23 export function oid(instance: any): stri | |||||
| 18 | return (instance[_oid] = "oid_" + (++_nextOid)); |
|
17 | return (instance[_oid] = "oid_" + (++_nextOid)); | |
| 19 | } |
|
18 | } | |
| 20 |
|
19 | |||
|
|
20 | const cancellationNone: ICancellation = { | |||
|
|
21 | isSupported(): boolean { | |||
|
|
22 | return false; | |||
|
|
23 | }, | |||
|
|
24 | ||||
|
|
25 | throwIfRequested(): void { | |||
|
|
26 | }, | |||
|
|
27 | ||||
|
|
28 | isRequested(): boolean { | |||
|
|
29 | return false; | |||
|
|
30 | }, | |||
|
|
31 | ||||
|
|
32 | register(_cb: (e: any) => void): IDestroyable { | |||
|
|
33 | return destroyed; | |||
|
|
34 | } | |||
|
|
35 | }; | |||
|
|
36 | ||||
| 21 | export function keys<T>(arg: T): (Extract<keyof T, string>)[] { |
|
37 | export function keys<T>(arg: T): (Extract<keyof T, string>)[] { | |
| 22 | return isObject(arg) && arg ? Object.keys(arg) as (Extract<keyof T, string>)[] : []; |
|
38 | return isObject(arg) && arg ? Object.keys(arg) as (Extract<keyof T, string>)[] : []; | |
| 23 | } |
|
39 | } | |
| @@ -272,7 +288,7 export function delegate(target: any, _m | |||||
| 272 | }; |
|
288 | }; | |
| 273 | } |
|
289 | } | |
| 274 |
|
290 | |||
| 275 |
export function delay(timeMs: number, ct = |
|
291 | export function delay(timeMs: number, ct = cancellationNone) { | |
| 276 | ct.throwIfRequested(); |
|
292 | ct.throwIfRequested(); | |
| 277 | return new Promise((resolve, reject) => { |
|
293 | return new Promise((resolve, reject) => { | |
| 278 | const h = ct.register(e => { |
|
294 | const h = ct.register(e => { | |
General Comments 0
You need to be logged in to leave comments.
Login now
