@@ -122,18 +122,24 @@ export const enum ChoreType {
122
122
/* order of elements (not encoded here) */
123
123
MICRO /* **************************** */ = 0b0000_1111 ,
124
124
125
- /** Ensure tha the QRL promise is resolved before processing next chores in the queue */
125
+ /** Ensure that the QRL promise is resolved before processing next chores in the queue */
126
126
QRL_RESOLVE /* ********************** */ = 0b0000_0001 ,
127
- RESOURCE /* ************************* */ = 0b0000_0010 ,
128
- TASK /* ***************************** */ = 0b0000_0011 ,
129
- NODE_DIFF /* ************************ */ = 0b0000_0100 ,
130
- NODE_PROP /* ************************ */ = 0b0000_0101 ,
131
- COMPONENT_SSR /* ******************** */ = 0b0000_0110 ,
132
- COMPONENT /* ************************ */ = 0b0000_0111 ,
133
- RECOMPUTE_AND_SCHEDULE_EFFECTS /* *** */ = 0b0000_1000 ,
127
+ RUN_QRL ,
128
+ RESOURCE ,
129
+ TASK ,
130
+ NODE_DIFF ,
131
+ NODE_PROP ,
132
+ COMPONENT_SSR ,
133
+ COMPONENT ,
134
+ RECOMPUTE_AND_SCHEDULE_EFFECTS ,
135
+
136
+ // Next macro level
134
137
JOURNAL_FLUSH /* ******************** */ = 0b0001_0000 ,
138
+ // Next macro level
135
139
VISIBLE /* ************************** */ = 0b0010_0000 ,
140
+ // Next macro level
136
141
CLEANUP_VISIBLE /* ****************** */ = 0b0011_0000 ,
142
+ // Next macro level
137
143
WAIT_FOR_ALL /* ********************* */ = 0b1111_1111 ,
138
144
}
139
145
@@ -202,6 +208,12 @@ export const createScheduler = (
202
208
type : ChoreType . TASK | ChoreType . VISIBLE | ChoreType . RESOURCE ,
203
209
task : Task
204
210
) : ValueOrPromise < void > ;
211
+ function schedule (
212
+ type : ChoreType . RUN_QRL ,
213
+ ignore : null ,
214
+ target : QRLInternal < ( ...args : unknown [ ] ) => unknown > ,
215
+ args : unknown [ ]
216
+ ) : ValueOrPromise < void > ;
205
217
function schedule (
206
218
type : ChoreType . COMPONENT ,
207
219
host : HostElement ,
@@ -234,7 +246,10 @@ export const createScheduler = (
234
246
targetOrQrl : ChoreTarget | string | null = null ,
235
247
payload : any = null
236
248
) : ValueOrPromise < any > {
237
- const runLater : boolean = type !== ChoreType . WAIT_FOR_ALL && type !== ChoreType . COMPONENT_SSR ;
249
+ const runLater : boolean =
250
+ type !== ChoreType . WAIT_FOR_ALL &&
251
+ type !== ChoreType . COMPONENT_SSR &&
252
+ type !== ChoreType . RUN_QRL ;
238
253
const isTask =
239
254
type === ChoreType . TASK ||
240
255
type === ChoreType . VISIBLE ||
@@ -289,15 +304,19 @@ export const createScheduler = (
289
304
return runUptoChore . $promise$ ;
290
305
}
291
306
while ( choreQueue . length ) {
292
- const nextChore = choreQueue . shift ( ) ! ;
307
+ const nextChore = choreQueue [ 0 ] ;
293
308
const order = choreComparator ( nextChore , runUptoChore , rootVNode ) ;
294
- if ( order === null ) {
295
- continue ;
296
- }
297
- if ( order > 0 ) {
309
+ if ( order !== null && order > 0 ) {
298
310
// we have processed all of the chores up to and including the given chore.
299
311
break ;
300
312
}
313
+ // We can take the chore out of the queue
314
+ choreQueue . shift ( ) ;
315
+ if ( order === null ) {
316
+ // There was an error with the chore.
317
+ DEBUG && debugTrace ( 'skip chore' , nextChore , currentChore , choreQueue ) ;
318
+ continue ;
319
+ }
301
320
const isDeletedVNode = vNodeAlreadyDeleted ( nextChore ) ;
302
321
if (
303
322
isDeletedVNode &&
@@ -364,6 +383,12 @@ export const createScheduler = (
364
383
const result = runResource ( chore . $payload$ as ResourceDescriptor < TaskFn > , container , host ) ;
365
384
returnValue = isDomContainer ( container ) ? null : result ;
366
385
break ;
386
+ case ChoreType . RUN_QRL :
387
+ {
388
+ const fn = ( chore . $target$ as QRLInternal < ( ...args : unknown [ ] ) => unknown > ) . getFn ( ) ;
389
+ returnValue = fn ( ...( chore . $payload$ as unknown [ ] ) ) ;
390
+ }
391
+ break ;
367
392
case ChoreType . TASK :
368
393
returnValue = runTask ( chore . $payload$ as Task < TaskFn , TaskFn > , container , host ) ;
369
394
break ;
@@ -423,11 +448,11 @@ export const createScheduler = (
423
448
}
424
449
}
425
450
return maybeThenPassError ( returnValue , ( value ) => {
426
- DEBUG && debugTrace ( 'execute.DONE' , null , currentChore , choreQueue ) ;
427
451
if ( currentChore ) {
428
452
currentChore . $executed$ = true ;
429
453
currentChore . $resolve$ ?.( value ) ;
430
454
}
455
+ DEBUG && debugTrace ( 'execute.DONE' , null , currentChore , choreQueue ) ;
431
456
currentChore = null ;
432
457
return ( chore . $returnValue$ = value ) ;
433
458
} ) ;
@@ -476,7 +501,6 @@ function choreComparator(a: Chore, b: Chore, rootVNode: ElementVNode | null): nu
476
501
const aHost = a . $host$ ;
477
502
const bHost = b . $host$ ;
478
503
479
- // QRL_RESOLVE does not have a host.
480
504
if ( aHost !== bHost && aHost !== null && bHost !== null ) {
481
505
if ( vnode_isVNode ( aHost ) && vnode_isVNode ( bHost ) ) {
482
506
// we are running on the client.
@@ -511,13 +535,13 @@ function choreComparator(a: Chore, b: Chore, rootVNode: ElementVNode | null): nu
511
535
return idxDiff ;
512
536
}
513
537
514
- // If the host is the same, we need to compare the target.
538
+ // If the host is the same (or missing), and the type is the same, we need to compare the target.
515
539
if (
516
540
a . $target$ !== b . $target$ &&
517
- ( ( a . $type$ === ChoreType . QRL_RESOLVE && b . $type$ === ChoreType . QRL_RESOLVE ) ||
518
- ( a . $type$ === ChoreType . NODE_PROP && b . $type$ === ChoreType . NODE_PROP ) ||
519
- ( a . $type$ === ChoreType . RECOMPUTE_AND_SCHEDULE_EFFECTS &&
520
- b . $type$ === ChoreType . RECOMPUTE_AND_SCHEDULE_EFFECTS ) )
541
+ ( a . $type$ === ChoreType . QRL_RESOLVE ||
542
+ a . $type$ === ChoreType . RUN_QRL ||
543
+ a . $type$ === ChoreType . NODE_PROP ||
544
+ a . $type$ === ChoreType . RECOMPUTE_AND_SCHEDULE_EFFECTS )
521
545
) {
522
546
// 1 means that we are going to process chores as FIFO
523
547
return 1 ;
@@ -571,6 +595,7 @@ function debugChoreToString(chore: Chore): string {
571
595
(
572
596
{
573
597
[ ChoreType . QRL_RESOLVE ] : 'QRL_RESOLVE' ,
598
+ [ ChoreType . RUN_QRL ] : 'RUN_QRL' ,
574
599
[ ChoreType . RESOURCE ] : 'RESOURCE' ,
575
600
[ ChoreType . TASK ] : 'TASK' ,
576
601
[ ChoreType . NODE_DIFF ] : 'NODE_DIFF' ,
@@ -586,7 +611,7 @@ function debugChoreToString(chore: Chore): string {
586
611
) [ chore . $type$ ] || 'UNKNOWN: ' + chore . $type$ ;
587
612
const host = String ( chore . $host$ ) . replaceAll ( / \n .* / gim, '' ) ;
588
613
const qrlTarget = ( chore . $target$ as QRLInternal < any > ) ?. $symbol$ ;
589
- return `Chore(${ type } ${ chore . $type$ === ChoreType . QRL_RESOLVE ? qrlTarget : host } ${ chore . $idx$ } )` ;
614
+ return `Chore(${ type } ${ chore . $type$ === ChoreType . QRL_RESOLVE || chore . $type$ === ChoreType . RUN_QRL ? qrlTarget : host } ${ chore . $idx$ } )` ;
590
615
}
591
616
592
617
function debugTrace (
@@ -603,7 +628,9 @@ function debugTrace(
603
628
) ;
604
629
}
605
630
if ( currentChore ) {
606
- lines . push ( 'running: ' + debugChoreToString ( currentChore ) ) ;
631
+ lines . push (
632
+ `${ currentChore . $executed$ ? ' done' : 'running' } : ` + debugChoreToString ( currentChore )
633
+ ) ;
607
634
}
608
635
if ( queue ) {
609
636
queue . forEach ( ( chore , idx ) => {
0 commit comments