chore: inline `suspend` (#16755)

* chore: inline `suspend`

* invert condition
pull/16759/head
Rich Harris 6 days ago committed by GitHub
parent df13be8727
commit 808fbb4989
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -103,7 +103,7 @@ export {
save,
track_reactivity_loss
} from './reactivity/async.js';
export { flushSync as flush, suspend } from './reactivity/batch.js';
export { flushSync as flush } from './reactivity/batch.js';
export {
async_derived,
user_derived as derived,

@ -11,7 +11,7 @@ import {
set_active_effect,
set_active_reaction
} from '../runtime.js';
import { current_batch, suspend } from './batch.js';
import { Batch, current_batch } from './batch.js';
import {
async_derived,
current_async_effect,
@ -178,7 +178,13 @@ export function unset_context() {
* @param {() => Promise<void>} fn
*/
export async function async_body(fn) {
var unsuspend = suspend();
var boundary = get_boundary();
var batch = /** @type {Batch} */ (current_batch);
var pending = boundary.is_pending();
boundary.update_pending_count(1);
if (!pending) batch.increment();
var active = /** @type {Effect} */ (active_effect);
try {
@ -188,6 +194,15 @@ export async function async_body(fn) {
invoke_error_boundary(error, active);
}
} finally {
unsuspend();
boundary.update_pending_count(-1);
if (pending) {
batch.flush();
} else {
batch.activate();
batch.decrement();
}
unset_context();
}
}

@ -653,28 +653,6 @@ export function schedule_effect(signal) {
queued_root_effects.push(effect);
}
export function suspend() {
var boundary = get_boundary();
var batch = /** @type {Batch} */ (current_batch);
var pending = boundary.is_pending();
boundary.update_pending_count(1);
if (!pending) batch.increment();
return function unsuspend() {
boundary.update_pending_count(-1);
if (!pending) {
batch.activate();
batch.decrement();
} else {
batch.flush();
}
unset_context();
};
}
/**
* Forcibly remove all current batches, to prevent cross-talk between tests
*/

Loading…
Cancel
Save