(node, blockers = [], expressions = [], fn)
| 18 | * @param {(anchor: TemplateNode, ...deriveds: Value[]) => void} fn |
| 19 | */ |
| 20 | export function async(node, blockers = [], expressions = [], fn) { |
| 21 | var was_hydrating = hydrating; |
| 22 | var end = null; |
| 23 | |
| 24 | if (was_hydrating) { |
| 25 | hydrate_next(); |
| 26 | end = skip_nodes(false); |
| 27 | assign_nodes(node, end); // Necessary if this wraps the sole child of a block, else end marker can be wrong |
| 28 | } |
| 29 | |
| 30 | if (expressions.length === 0 && blockers.every((b) => b.settled)) { |
| 31 | fn(node); |
| 32 | |
| 33 | // This is necessary because it is not guaranteed that the render function will |
| 34 | // advance the hydration node to $.async's end marker: it may stop at an inner |
| 35 | // block's end marker (in case of an inner if block for example), but it also may |
| 36 | // stop at the correct $.async end marker (in case of component child) - hence |
| 37 | // we can't just use hydrate_next() |
| 38 | // TODO this feels indicative of a bug elsewhere; ideally we wouldn't need |
| 39 | // to double-traverse in the already-resolved case |
| 40 | if (was_hydrating) { |
| 41 | set_hydrate_node(end); |
| 42 | } |
| 43 | |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | if (was_hydrating) { |
| 48 | var previous_hydrate_node = hydrate_node; |
| 49 | set_hydrate_node(end); |
| 50 | } |
| 51 | |
| 52 | flatten(blockers, [], expressions, (values) => { |
| 53 | if (was_hydrating) { |
| 54 | set_hydrating(true); |
| 55 | set_hydrate_node(previous_hydrate_node); |
| 56 | } |
| 57 | |
| 58 | try { |
| 59 | // get values eagerly to avoid creating blocks if they reject |
| 60 | for (const d of values) get(d); |
| 61 | |
| 62 | fn(node, ...values); |
| 63 | } finally { |
| 64 | if (was_hydrating) { |
| 65 | set_hydrating(false); |
| 66 | } |
| 67 | } |
| 68 | }); |
| 69 | } |
nothing calls this directly
no test coverage detected