* Resolve the `id`. Returns the object immediately if it can be resolved, * and otherwise waits for the object to appear and calls `callback` once * it is resolved.
(id: Id, callback: (t: T) => void)
| 39 | * it is resolved. |
| 40 | */ |
| 41 | tryGet(id: Id, callback: (t: T) => void): T|null { |
| 42 | const obj = this.getForId(id); |
| 43 | if (!obj) { |
| 44 | const swallowTheError = (): void => {}; |
| 45 | void this.getOrCreatePromise(id).catch(swallowTheError).then(obj => { |
| 46 | if (obj) { |
| 47 | callback(obj); |
| 48 | } |
| 49 | }); |
| 50 | return null; |
| 51 | } |
| 52 | return obj; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Aborts all waiting and rejects all unresolved promises. |