|
|
|
@ -273,13 +273,15 @@ export function capture() {
|
|
|
|
|
var previous_reaction = active_reaction;
|
|
|
|
|
var previous_component_context = component_context;
|
|
|
|
|
|
|
|
|
|
return function restore() {
|
|
|
|
|
return function restore(should_exit = true) {
|
|
|
|
|
set_active_effect(previous_effect);
|
|
|
|
|
set_active_reaction(previous_reaction);
|
|
|
|
|
set_component_context(previous_component_context);
|
|
|
|
|
|
|
|
|
|
// prevent the active effect from outstaying its welcome
|
|
|
|
|
queue_post_micro_task(exit);
|
|
|
|
|
if (should_exit) {
|
|
|
|
|
queue_post_micro_task(exit);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -307,6 +309,21 @@ export function suspend() {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @template T
|
|
|
|
|
* @param {() => Promise<T>} fn
|
|
|
|
|
*/
|
|
|
|
|
export async function script_suspend(fn) {
|
|
|
|
|
const restore = capture();
|
|
|
|
|
const unsuspend = suspend();
|
|
|
|
|
try {
|
|
|
|
|
return await fn();
|
|
|
|
|
} finally {
|
|
|
|
|
restore(false);
|
|
|
|
|
unsuspend();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @template T
|
|
|
|
|
* @param {Promise<T>} promise
|
|
|
|
|