fix flushSync (should drain queue before calling the function)

async-another-try
Simon Holthausen 5 days ago
parent 31524c792e
commit 32f4451f2e
No known key found for this signature in database

@ -1001,7 +1001,7 @@ export class Batch {
if (current_batch === null) { if (current_batch === null) {
const batch = (current_batch = new Batch()); const batch = (current_batch = new Batch());
if (!is_processing && !is_flushing_sync) { if (!is_processing) {
queue_micro_task(() => { queue_micro_task(() => {
if (!batch.started) { if (!batch.started) {
batch.flush(); batch.flush();
@ -1124,9 +1124,7 @@ export function flushSync(fn) {
var result; var result;
if (fn) { if (fn) {
if (current_batch !== null && !current_batch.is_fork) { flushSync(); // drain queue via the lower while(true) part
current_batch.flush();
}
result = fn(); result = fn();
} }
@ -1464,15 +1462,21 @@ export function fork(fn) {
e.fork_timing(); e.fork_timing();
} }
var batch = Batch.ensure();
batch.is_fork = true;
batch_values = new Map();
wv_values = new Map();
var committed = false; var committed = false;
var settled = batch.settled(); /** @type {Promise<void>} */
var settled;
/** @type {Batch} */
var batch;
flushSync(fn); flushSync(() => {
batch = Batch.ensure();
batch.is_fork = true;
batch_values = new Map();
wv_values = new Map();
settled = batch.settled();
fn();
});
return { return {
commit: async () => { commit: async () => {

Loading…
Cancel
Save