|
|
|
@ -10,7 +10,7 @@ import {
|
|
|
|
set_current_reaction
|
|
|
|
set_current_reaction
|
|
|
|
} from '../../runtime.js';
|
|
|
|
} from '../../runtime.js';
|
|
|
|
import { destroy_effect, pause_effect, render_effect } from '../../reactivity/effects.js';
|
|
|
|
import { destroy_effect, pause_effect, render_effect } from '../../reactivity/effects.js';
|
|
|
|
import { INERT } from '../../constants.js';
|
|
|
|
import { DESTROYED, INERT } from '../../constants.js';
|
|
|
|
|
|
|
|
|
|
|
|
/** @returns {import('../../types.js').AwaitBlock} */
|
|
|
|
/** @returns {import('../../types.js').AwaitBlock} */
|
|
|
|
export function create_await_block() {
|
|
|
|
export function create_await_block() {
|
|
|
|
@ -83,11 +83,11 @@ export function await_block(anchor_node, get_input, pending_fn, then_fn, catch_f
|
|
|
|
return effect;
|
|
|
|
return effect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/** @param {import('#client').Effect} effect */
|
|
|
|
* @param {import('#client').Effect} effect
|
|
|
|
function pause(effect) {
|
|
|
|
* @param {any} block
|
|
|
|
if ((effect.f & DESTROYED) !== 0) return;
|
|
|
|
*/
|
|
|
|
const block = effect.block;
|
|
|
|
function pause(effect, block) {
|
|
|
|
|
|
|
|
pause_effect(effect, () => {
|
|
|
|
pause_effect(effect, () => {
|
|
|
|
// TODO make this unnecessary
|
|
|
|
// TODO make this unnecessary
|
|
|
|
const dom = block?.d;
|
|
|
|
const dom = block?.d;
|
|
|
|
@ -110,21 +110,13 @@ export function await_block(anchor_node, get_input, pending_fn, then_fn, catch_f
|
|
|
|
pending_effect = render_effect(() => pending_fn(anchor_node), (pending_block = {}), true);
|
|
|
|
pending_effect = render_effect(() => pending_fn(anchor_node), (pending_block = {}), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (then_effect) {
|
|
|
|
if (then_effect) pause(then_effect);
|
|
|
|
pause(then_effect, then_block);
|
|
|
|
if (catch_effect) pause(catch_effect);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (catch_effect) {
|
|
|
|
|
|
|
|
pause(catch_effect, catch_block);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
promise.then(
|
|
|
|
promise.then(
|
|
|
|
(value) => {
|
|
|
|
(value) => {
|
|
|
|
if (promise !== input) return;
|
|
|
|
if (promise !== input) return;
|
|
|
|
|
|
|
|
if (pending_effect) pause(pending_effect);
|
|
|
|
if (pending_effect) {
|
|
|
|
|
|
|
|
pause(pending_effect, pending_block);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (then_fn) {
|
|
|
|
if (then_fn) {
|
|
|
|
then_effect = create_effect(then_fn, value, (then_block = {}));
|
|
|
|
then_effect = create_effect(then_fn, value, (then_block = {}));
|
|
|
|
@ -132,10 +124,7 @@ export function await_block(anchor_node, get_input, pending_fn, then_fn, catch_f
|
|
|
|
},
|
|
|
|
},
|
|
|
|
(error) => {
|
|
|
|
(error) => {
|
|
|
|
if (promise !== input) return;
|
|
|
|
if (promise !== input) return;
|
|
|
|
|
|
|
|
if (pending_effect) pause(pending_effect);
|
|
|
|
if (pending_effect) {
|
|
|
|
|
|
|
|
pause(pending_effect, pending_block);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (catch_fn) {
|
|
|
|
if (catch_fn) {
|
|
|
|
catch_effect = create_effect(catch_fn, error, (catch_block = {}));
|
|
|
|
catch_effect = create_effect(catch_fn, error, (catch_block = {}));
|
|
|
|
@ -143,9 +132,8 @@ export function await_block(anchor_node, get_input, pending_fn, then_fn, catch_f
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (pending_effect) {
|
|
|
|
if (pending_effect) pause(pending_effect);
|
|
|
|
pause(pending_effect, pending_block);
|
|
|
|
if (catch_effect) pause(catch_effect);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (then_effect) {
|
|
|
|
if (then_effect) {
|
|
|
|
destroy_effect(then_effect);
|
|
|
|
destroy_effect(then_effect);
|
|
|
|
@ -155,10 +143,6 @@ export function await_block(anchor_node, get_input, pending_fn, then_fn, catch_f
|
|
|
|
if (then_fn) {
|
|
|
|
if (then_fn) {
|
|
|
|
then_effect = render_effect(() => then_fn(anchor_node, input), (then_block = {}), true);
|
|
|
|
then_effect = render_effect(() => then_fn(anchor_node, input), (then_block = {}), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (catch_effect) {
|
|
|
|
|
|
|
|
pause(catch_effect, catch_block);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, block);
|
|
|
|
}, block);
|
|
|
|
|
|
|
|
|
|
|
|
|