@@ -170,8 +170,8 @@ export const createScheduler = (
170
170
171
171
function schedule (
172
172
type : ChoreType . QRL_RESOLVE ,
173
- ignore0 : null ,
174
- ignore1 : QRLInternal < any >
173
+ ignore : null ,
174
+ target : QRLInternal < any >
175
175
) : ValueOrPromise < void > ;
176
176
function schedule ( type : ChoreType . JOURNAL_FLUSH ) : ValueOrPromise < void > ;
177
177
function schedule ( type : ChoreType . WAIT_FOR_ALL ) : ValueOrPromise < void > ;
@@ -369,7 +369,7 @@ export const createScheduler = (
369
369
break ;
370
370
case ChoreType . QRL_RESOLVE : {
371
371
const target = chore . $target$ as QRLInternal < any > ;
372
- returnValue = target . resolve ( ) ;
372
+ returnValue = ! target . resolved ? target . resolve ( ) : null ;
373
373
break ;
374
374
}
375
375
}
@@ -417,7 +417,12 @@ function choreComparator(a: Chore, b: Chore, shouldThrowOnHostMismatch: boolean)
417
417
if ( a . $type$ !== ChoreType . JOURNAL_FLUSH ) {
418
418
const aHost = a . $host$ ;
419
419
const bHost = b . $host$ ;
420
- if ( aHost !== bHost ) {
420
+
421
+ const aHostIsQrlResolve = a . $type$ === ChoreType . QRL_RESOLVE ;
422
+ const bHostIsQrlResolve = b . $type$ === ChoreType . QRL_RESOLVE ;
423
+
424
+ // QRL_RESOLVE does not have a host.
425
+ if ( aHost !== bHost && ! aHostIsQrlResolve && ! bHostIsQrlResolve ) {
421
426
if ( vnode_isVNode ( aHost ) && vnode_isVNode ( bHost ) ) {
422
427
// we are running on the client.
423
428
const hostDiff = vnode_documentPosition ( aHost , bHost ) ;
@@ -444,6 +449,18 @@ function choreComparator(a: Chore, b: Chore, shouldThrowOnHostMismatch: boolean)
444
449
return microTypeDiff ;
445
450
}
446
451
452
+ /**
453
+ * QRL_RESOLVE is a special case. It does not have a host nor $idx$. We want to process
454
+ * QRL_RESOLVE chores as FIFO, so we need to return 1.
455
+ */
456
+ if (
457
+ aHostIsQrlResolve &&
458
+ bHostIsQrlResolve &&
459
+ ( a . $target$ as QRLInternal < any > ) . $symbol$ !== ( b . $target$ as QRLInternal < any > ) . $symbol$
460
+ ) {
461
+ return 1 ;
462
+ }
463
+
447
464
const idxDiff = toNumber ( a . $idx$ ) - toNumber ( b . $idx$ ) ;
448
465
if ( idxDiff !== 0 ) {
449
466
return idxDiff ;
@@ -453,26 +470,6 @@ function choreComparator(a: Chore, b: Chore, shouldThrowOnHostMismatch: boolean)
453
470
return 0 ;
454
471
}
455
472
456
- export const intraHostPredicate = ( a : Chore , b : Chore ) : number => {
457
- const idxDiff = toNumber ( a . $idx$ ) - toNumber ( b . $idx$ ) ;
458
- if ( idxDiff !== 0 ) {
459
- return idxDiff ;
460
- }
461
- const typeDiff = a . $type$ - b . $type$ ;
462
- if ( typeDiff !== 0 ) {
463
- return typeDiff ;
464
- }
465
- if ( a . $payload$ !== b . $payload$ ) {
466
- return 0 ;
467
- }
468
- if ( a . $payload$ instanceof Task && b . $payload$ instanceof Task ) {
469
- const aHash = a . $payload$ . $qrl$ . $hash$ ;
470
- const bHash = b . $payload$ . $qrl$ . $hash$ ;
471
- return aHash === bHash ? 0 : aHash < bHash ? - 1 : 1 ;
472
- }
473
- return 0 ;
474
- } ;
475
-
476
473
function sortedFindIndex ( sortedArray : Chore [ ] , value : Chore ) : number {
477
474
/// We need to ensure that the `queue` is sorted by priority.
478
475
/// 1. Find a place where to insert into.
@@ -525,7 +522,8 @@ function debugChoreToString(chore: Chore): string {
525
522
} as any
526
523
) [ chore . $type$ ] || 'UNKNOWN: ' + chore . $type$ ;
527
524
const host = String ( chore . $host$ ) . replaceAll ( / \n .* / gim, '' ) ;
528
- return `Chore(${ type } ${ host } ${ chore . $idx$ } )` ;
525
+ const qrlTarget = ( chore . $target$ as QRLInternal < any > ) . $symbol$ ;
526
+ return `Chore(${ type } ${ chore . $type$ === ChoreType . QRL_RESOLVE ? qrlTarget : host } ${ chore . $idx$ } )` ;
529
527
}
530
528
531
529
function debugTrace (
0 commit comments