( registry: AtomRegistry.AtomRegistry, atom: Atom.Atom<AsyncResult.AsyncResult<A, E>>, suspendOnWaiting: boolean )
| 304 | } |
| 305 | |
| 306 | function atomToPromise<A, E>( |
| 307 | registry: AtomRegistry.AtomRegistry, |
| 308 | atom: Atom.Atom<AsyncResult.AsyncResult<A, E>>, |
| 309 | suspendOnWaiting: boolean |
| 310 | ) { |
| 311 | const registries = suspendOnWaiting ? atomPromiseMap.suspendOnWaiting : atomPromiseMap.default |
| 312 | let map = registries.get(registry) |
| 313 | if (map === undefined) { |
| 314 | map = new WeakMap() |
| 315 | registries.set(registry, map) |
| 316 | } |
| 317 | let promise = map.get(atom) |
| 318 | if (promise !== undefined) { |
| 319 | return promise |
| 320 | } |
| 321 | promise = new Promise<void>((resolve) => { |
| 322 | const dispose = registry.subscribe(atom, (result) => { |
| 323 | if (result._tag === "Initial" || (suspendOnWaiting && result.waiting)) { |
| 324 | return |
| 325 | } |
| 326 | setTimeout(dispose, 1000) |
| 327 | resolve() |
| 328 | map.delete(atom) |
| 329 | }) |
| 330 | }) |
| 331 | map.set(atom, promise) |
| 332 | return promise |
| 333 | } |
| 334 | |
| 335 | function atomResultOrSuspend<A, E>( |
| 336 | registry: AtomRegistry.AtomRegistry, |
no test coverage detected