@@ -170,8 +170,8 @@ export const createScheduler = (
170170
171171 function schedule (
172172 type : ChoreType . QRL_RESOLVE ,
173- ignore0 : null ,
174- ignore1 : QRLInternal < any >
173+ ignore : null ,
174+ target : QRLInternal < any >
175175 ) : ValueOrPromise < void > ;
176176 function schedule ( type : ChoreType . JOURNAL_FLUSH ) : ValueOrPromise < void > ;
177177 function schedule ( type : ChoreType . WAIT_FOR_ALL ) : ValueOrPromise < void > ;
@@ -369,7 +369,7 @@ export const createScheduler = (
369369 break ;
370370 case ChoreType . QRL_RESOLVE : {
371371 const target = chore . $target$ as QRLInternal < any > ;
372- returnValue = target . resolve ( ) ;
372+ returnValue = ! target . resolved ? target . resolve ( ) : null ;
373373 break ;
374374 }
375375 }
@@ -417,7 +417,12 @@ function choreComparator(a: Chore, b: Chore, shouldThrowOnHostMismatch: boolean)
417417 if ( a . $type$ !== ChoreType . JOURNAL_FLUSH ) {
418418 const aHost = a . $host$ ;
419419 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 ) {
421426 if ( vnode_isVNode ( aHost ) && vnode_isVNode ( bHost ) ) {
422427 // we are running on the client.
423428 const hostDiff = vnode_documentPosition ( aHost , bHost ) ;
@@ -444,6 +449,18 @@ function choreComparator(a: Chore, b: Chore, shouldThrowOnHostMismatch: boolean)
444449 return microTypeDiff ;
445450 }
446451
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+
447464 const idxDiff = toNumber ( a . $idx$ ) - toNumber ( b . $idx$ ) ;
448465 if ( idxDiff !== 0 ) {
449466 return idxDiff ;
@@ -453,26 +470,6 @@ function choreComparator(a: Chore, b: Chore, shouldThrowOnHostMismatch: boolean)
453470 return 0 ;
454471}
455472
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-
476473function sortedFindIndex ( sortedArray : Chore [ ] , value : Chore ) : number {
477474 /// We need to ensure that the `queue` is sorted by priority.
478475 /// 1. Find a place where to insert into.
@@ -525,7 +522,8 @@ function debugChoreToString(chore: Chore): string {
525522 } as any
526523 ) [ chore . $type$ ] || 'UNKNOWN: ' + chore . $type$ ;
527524 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$ } )` ;
529527}
530528
531529function debugTrace (
0 commit comments