aa-fork
Rich Harris 8 months ago
parent 72f30dd892
commit 0f05cb1cfa

@ -40,22 +40,39 @@ export function decrement_fork(fork) {
queue_micro_task(() => { queue_micro_task(() => {
if (fork.pending === 0) { if (fork.pending === 0) {
// TODO if the state that was originally set inside the if (is_valid(fork)) {
// fork callback was updated in the meantime, reject // TODO we also need to handle a case like
// the fork. Also need to handle a case like // `{#if a || b}` where the fork makes `a`
// `{#if a || b}` where the fork makes `a` // truthy but `b` became truthy in the
// truthy but `b` became truthy in the // meantime — requires a 'rebase'
// meantime — requires a 'rebase' fork.callback();
fork.callback(); } else {
fork.callback(new Error('stale fork'));
}
} }
}); });
} }
/**
* @param {Fork} fork
*/
function is_valid(fork) {
for (const [source, source_fork] of fork.sources) {
if (source.wv > source_fork.wv) {
return false;
}
}
return true;
}
/** /**
* @param {Fork} fork * @param {Fork} fork
*/ */
function apply_fork(fork) { function apply_fork(fork) {
// TODO check the fork is still valid and error otherwise if (!is_valid(fork)) {
throw new Error('stale fork');
}
for (const [source, saved] of fork.sources) { for (const [source, saved] of fork.sources) {
source.v = saved.next_v; source.v = saved.next_v;

Loading…
Cancel
Save