(node, get_input, pending_fn, then_fn, catch_fn)
| 34 | * @returns {void} |
| 35 | */ |
| 36 | export function await_block(node, get_input, pending_fn, then_fn, catch_fn) { |
| 37 | if (hydrating) { |
| 38 | hydrate_next(); |
| 39 | } |
| 40 | |
| 41 | var runes = is_runes(); |
| 42 | |
| 43 | var v = /** @type {V} */ (UNINITIALIZED); |
| 44 | var value = runes ? source(v) : mutable_source(v, false, false); |
| 45 | var error = runes ? source(v) : mutable_source(v, false, false); |
| 46 | |
| 47 | if (DEV) { |
| 48 | value.label = '{#await ...} value'; |
| 49 | error.label = '{#await ...} error'; |
| 50 | } |
| 51 | |
| 52 | var branches = new BranchManager(node); |
| 53 | |
| 54 | block(() => { |
| 55 | var batch = /** @type {Batch} */ (current_batch); |
| 56 | var input = get_input(); |
| 57 | |
| 58 | var destroyed = false; |
| 59 | |
| 60 | /** Whether or not there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */ |
| 61 | // @ts-ignore coercing `node` to a `Comment` causes TypeScript and Prettier to fight |
| 62 | let mismatch = hydrating && is_promise(input) === (node.data === HYDRATION_START_ELSE); |
| 63 | |
| 64 | if (mismatch) { |
| 65 | // Hydration mismatch: remove everything inside the anchor and start fresh |
| 66 | set_hydrate_node(skip_nodes()); |
| 67 | set_hydrating(false); |
| 68 | } |
| 69 | |
| 70 | if (is_promise(input)) { |
| 71 | var restore = capture(); |
| 72 | var resolved = false; |
| 73 | |
| 74 | /** |
| 75 | * @param {() => void} fn |
| 76 | */ |
| 77 | const resolve = (fn) => { |
| 78 | if (destroyed) return; |
| 79 | |
| 80 | resolved = true; |
| 81 | // We don't want to restore the previous batch here; {#await} blocks don't follow the async logic |
| 82 | // we have elsewhere, instead pending/resolve/fail states are each their own batch so to speak. |
| 83 | restore(false); |
| 84 | // ...but it might still be set here. That means a `save(...)` has restored it — but that batch will |
| 85 | // likely already have been committed by the time it resolves, and this resolve should be processed |
| 86 | // in a separate batch. We're not using batch.deactivate()/activate() above because get_input() |
| 87 | // could write to sources, which would then incorrectly create a new batch or could mess with |
| 88 | // async_derived expecting a current_batch to exist. |
| 89 | if (current_batch === batch) { |
| 90 | batch.deactivate(); |
| 91 | } |
| 92 | // Make sure we have a batch, since the branch manager expects one to exist |
| 93 | Batch.ensure(); |
nothing calls this directly
no test coverage detected