@@ -43,6 +43,8 @@ function parseArgs() {
43
43
return [ target , method , args ] ;
44
44
}
45
45
46
+ let UUID = 0 ;
47
+
46
48
export default class Backburner {
47
49
public static Queue = Queue ;
48
50
@@ -327,25 +329,7 @@ export default class Backburner {
327
329
}
328
330
}
329
331
330
- let onError = getOnError ( this . options ) ;
331
- let executeAt = this . _platform . now ( ) + wait ;
332
-
333
- let fn ;
334
- if ( onError ) {
335
- fn = function ( ) {
336
- try {
337
- method . apply ( target , args ) ;
338
- } catch ( e ) {
339
- onError ( e ) ;
340
- }
341
- } ;
342
- } else {
343
- fn = function ( ) {
344
- method . apply ( target , args ) ;
345
- } ;
346
- }
347
-
348
- return this . _setTimeout ( fn , executeAt ) ;
332
+ return this . _setTimeout ( target , method , args , wait ) ;
349
333
}
350
334
351
335
public throttle < T > ( target : T , methodName : keyof T , wait ?: number | string , immediate ?: boolean ) : Timer ;
@@ -530,9 +514,9 @@ export default class Backburner {
530
514
if ( ! timer ) { return false ; }
531
515
let timerType = typeof timer ;
532
516
533
- if ( timerType === 'number' || timerType === 'string' ) { // we're cancelling a throttle or debounce
517
+ if ( timerType === 'number' ) { // we're cancelling a throttle or debounce
534
518
return this . _cancelItem ( timer , this . _throttlers ) || this . _cancelItem ( timer , this . _debouncees ) ;
535
- } else if ( timerType === 'function ' ) { // we're cancelling a setTimeout
519
+ } else if ( timerType === 'string ' ) { // we're cancelling a setTimeout
536
520
return this . _cancelLaterTimer ( timer ) ;
537
521
} else if ( timerType === 'object' && timer . queue && timer . method ) { // we're cancelling a deferOnce
538
522
return timer . queue . cancel ( timer ) ;
@@ -586,31 +570,34 @@ export default class Backburner {
586
570
}
587
571
}
588
572
589
- private _setTimeout ( fn , executeAt ) {
573
+ private _setTimeout ( target , method , args , wait ) {
574
+ let stack = this . DEBUG ? new Error ( ) : undefined ;
575
+ let executeAt = this . _platform . now ( ) + wait ;
576
+ let id = ( UUID ++ ) + '' ;
577
+
590
578
if ( this . _timers . length === 0 ) {
591
- this . _timers . push ( executeAt , fn ) ;
579
+ this . _timers . push ( executeAt , id , target , method , args , stack ) ;
592
580
this . _installTimerTimeout ( ) ;
593
- return fn ;
581
+ return id ;
594
582
}
595
583
596
584
// find position to insert
597
585
let i = searchTimer ( executeAt , this . _timers ) ;
598
-
599
- this . _timers . splice ( i , 0 , executeAt , fn ) ;
586
+ this . _timers . splice ( i , 0 , executeAt , id , target , method , args , stack ) ;
600
587
601
588
// we should be the new earliest timer if i == 0
602
589
if ( i === 0 ) {
603
590
this . _reinstallTimerTimeout ( ) ;
604
591
}
605
592
606
- return fn ;
593
+ return id ;
607
594
}
608
595
609
596
private _cancelLaterTimer ( timer ) {
610
- for ( let i = 1 ; i < this . _timers . length ; i += 2 ) {
597
+ for ( let i = 1 ; i < this . _timers . length ; i += 6 ) {
611
598
if ( this . _timers [ i ] === timer ) {
612
599
i = i - 1 ;
613
- this . _timers . splice ( i , 2 ) ; // remove the two elements
600
+ this . _timers . splice ( i , 6 ) ;
614
601
if ( i === 0 ) {
615
602
this . _reinstallTimerTimeout ( ) ;
616
603
}
@@ -662,15 +649,19 @@ export default class Backburner {
662
649
663
650
private _scheduleExpiredTimers ( ) {
664
651
let timers = this . _timers ;
665
- let l = timers . length ;
666
652
let i = 0 ;
653
+ let l = timers . length ;
667
654
let defaultQueue = this . options . defaultQueue ;
668
655
let n = this . _platform . now ( ) ;
669
- for ( ; i < l ; i += 2 ) {
656
+
657
+ for ( ; i < l ; i += 6 ) {
670
658
let executeAt = timers [ i ] ;
671
659
if ( executeAt <= n ) {
672
- let fn = timers [ i + 1 ] ;
673
- this . schedule ( defaultQueue , null , fn ) ;
660
+ let target = timers [ i + 2 ] ;
661
+ let method = timers [ i + 3 ] ;
662
+ let args = timers [ i + 4 ] ;
663
+ let stack = timers [ i + 5 ] ;
664
+ this . currentInstance ! . schedule ( defaultQueue , target , method , args , false , stack ) ;
674
665
} else {
675
666
break ;
676
667
}
0 commit comments