1
1
import PromisePolyfill from './Promise' ;
2
2
import { requestAnimFrame } from './util' ;
3
- import { isFunction , isNil , isNumber } from './util/common' ;
3
+ import { isFunction , isNil , isNumber , now } from './util/common' ;
4
4
import { getGlobalWorkerPool } from './worker/WorkerPool' ;
5
5
import Browser from './Browser' ;
6
6
import GlobalConfig from '../GlobalConfig' ;
@@ -87,8 +87,9 @@ function loop() {
87
87
broadcastIdleMessage = ! broadcastIdleMessage ;
88
88
}
89
89
90
+ let loopFrameTime = now ( ) ;
90
91
function frameLoop ( deadline ) {
91
- const { idleTimeRemaining, idleLog, idleTimeout } = GlobalConfig ;
92
+ const { idleTimeRemaining, idleLog, idleTimeout, idleForceTimeThreshold } = GlobalConfig ;
92
93
if ( Browser . requestIdleCallback ) {
93
94
if ( deadline && deadline . timeRemaining ) {
94
95
const t = deadline . timeRemaining ( ) ;
@@ -97,8 +98,16 @@ function frameLoop(deadline) {
97
98
console . error ( 'idle timeout in' , idleTimeout ) ;
98
99
}
99
100
loop ( ) ;
100
- } else if ( t <= idleTimeRemaining && idleLog ) {
101
- console . warn ( 'currrent page is busy,the timeRemaining is' , t ) ;
101
+ loopFrameTime = now ( ) ;
102
+ } else {
103
+ const time = now ( ) ;
104
+ if ( time - loopFrameTime > idleForceTimeThreshold ) {
105
+ loop ( ) ;
106
+ loopFrameTime = now ( ) ;
107
+ }
108
+ if ( t <= idleTimeRemaining && idleLog ) {
109
+ console . warn ( 'currrent page is busy,the timeRemaining is' , t ) ;
110
+ }
102
111
}
103
112
}
104
113
requestIdleCallback ( frameLoop , { timeout : idleTimeout } ) ;
0 commit comments