@@ -32,6 +32,14 @@ const noop = function() {};
32
32
33
33
const DISABLE_SCHEDULE = Object . freeze ( [ ] ) ;
34
34
35
+ interface ConsoleWithCreateTask extends Console {
36
+ createTask ( name : string ) : ConsoleTask ;
37
+ }
38
+
39
+ interface ConsoleTask {
40
+ run < T > ( f : ( ) => T ) : T ;
41
+ }
42
+
35
43
function parseArgs ( ...args : any [ ] ) ;
36
44
function parseArgs ( ) {
37
45
let length = arguments . length ;
@@ -163,6 +171,7 @@ export default class Backburner {
163
171
public static buildNext = buildNext ;
164
172
165
173
public DEBUG = false ;
174
+ public ASYNC_STACKS = false ;
166
175
167
176
public currentInstance : DeferredActionQueues | null = null ;
168
177
@@ -371,7 +380,8 @@ export default class Backburner {
371
380
scheduleCount ++ ;
372
381
let [ target , method , args ] = parseArgs ( ..._args ) ;
373
382
let stack = this . DEBUG ? new Error ( ) : undefined ;
374
- return this . _ensureInstance ( ) . schedule ( queueName , target , method , args , false , stack ) ;
383
+ let consoleTask = this . createTask ( queueName , method ) ;
384
+ return this . _ensureInstance ( ) . schedule ( queueName , target , method , args , false , stack , consoleTask ) ;
375
385
}
376
386
377
387
/*
@@ -385,7 +395,8 @@ export default class Backburner {
385
395
public scheduleIterable ( queueName : string , iterable : ( ) => Iterable ) {
386
396
scheduleIterableCount ++ ;
387
397
let stack = this . DEBUG ? new Error ( ) : undefined ;
388
- return this . _ensureInstance ( ) . schedule ( queueName , null , iteratorDrain , [ iterable ] , false , stack ) ;
398
+ let consoleTask = this . createTask ( queueName , null ) ;
399
+ return this . _ensureInstance ( ) . schedule ( queueName , null , iteratorDrain , [ iterable ] , false , stack , consoleTask ) ;
389
400
}
390
401
391
402
/**
@@ -406,7 +417,8 @@ export default class Backburner {
406
417
scheduleOnceCount ++ ;
407
418
let [ target , method , args ] = parseArgs ( ..._args ) ;
408
419
let stack = this . DEBUG ? new Error ( ) : undefined ;
409
- return this . _ensureInstance ( ) . schedule ( queueName , target , method , args , true , stack ) ;
420
+ let consoleTask = this . createTask ( queueName , method ) ;
421
+ return this . _ensureInstance ( ) . schedule ( queueName , target , method , args , true , stack , consoleTask ) ;
410
422
}
411
423
412
424
/**
@@ -525,7 +537,8 @@ export default class Backburner {
525
537
_timers [ argIndex ] = args ;
526
538
} else {
527
539
let stack = this . _timers [ index + 5 ] ;
528
- this . _timers . splice ( i , 0 , executeAt , timerId , target , method , args , stack ) ;
540
+ let consoleTask = this . _timers [ index + 6 ] ;
541
+ this . _timers . splice ( i , 0 , executeAt , timerId , target , method , args , stack , consoleTask ) ;
529
542
this . _timers . splice ( index , TIMERS_OFFSET ) ;
530
543
}
531
544
@@ -666,16 +679,17 @@ export default class Backburner {
666
679
667
680
private _later ( target , method , args , wait ) {
668
681
let stack = this . DEBUG ? new Error ( ) : undefined ;
682
+ let consoleTask = this . createTask ( "(timer)" , method ) ;
669
683
let executeAt = this . _platform . now ( ) + wait ;
670
684
let id = UUID ++ ;
671
685
672
686
if ( this . _timers . length === 0 ) {
673
- this . _timers . push ( executeAt , id , target , method , args , stack ) ;
687
+ this . _timers . push ( executeAt , id , target , method , args , stack , consoleTask ) ;
674
688
this . _installTimerTimeout ( ) ;
675
689
} else {
676
690
// find position to insert
677
691
let i = searchTimer ( executeAt , this . _timers ) ;
678
- this . _timers . splice ( i , 0 , executeAt , id , target , method , args , stack ) ;
692
+ this . _timers . splice ( i , 0 , executeAt , id , target , method , args , stack , consoleTask ) ;
679
693
680
694
// always reinstall since it could be out of sync
681
695
this . _reinstallTimerTimeout ( ) ;
@@ -741,7 +755,8 @@ export default class Backburner {
741
755
let target = timers [ i + 2 ] ;
742
756
let method = timers [ i + 3 ] ;
743
757
let stack = timers [ i + 5 ] ;
744
- this . currentInstance ! . schedule ( defaultQueue , target , method , args , false , stack ) ;
758
+ let consoleTask = timers [ i + 6 ] ;
759
+ this . currentInstance ! . schedule ( defaultQueue , target , method , args , false , stack , consoleTask ) ;
745
760
}
746
761
}
747
762
@@ -792,4 +807,12 @@ export default class Backburner {
792
807
793
808
this . _autorun = true ;
794
809
}
810
+
811
+ private createTask ( queueName , method ) {
812
+ if ( this . ASYNC_STACKS && console [ "createTask" ] ) {
813
+ return ( < ConsoleWithCreateTask > console ) . createTask (
814
+ `runloop ${ queueName } | ${ method ?. name || "<anonymous>" } `
815
+ ) ;
816
+ }
817
+ }
795
818
}
0 commit comments