11import PromisePolyfill from './Promise' ;
22import { requestAnimFrame } from './util' ;
3- import { isFunction , isNil , isNumber } from './util/common' ;
3+ import { isFunction , isNil , isNumber , now } from './util/common' ;
44import { getGlobalWorkerPool } from './worker/WorkerPool' ;
55import Browser from './Browser' ;
66import GlobalConfig from '../GlobalConfig' ;
@@ -87,8 +87,9 @@ function loop() {
8787 broadcastIdleMessage = ! broadcastIdleMessage ;
8888}
8989
90+ let loopFrameTime = now ( ) ;
9091function frameLoop ( deadline ) {
91- const { idleTimeRemaining, idleLog, idleTimeout } = GlobalConfig ;
92+ const { idleTimeRemaining, idleLog, idleTimeout, idleForceTimeThreshold } = GlobalConfig ;
9293 if ( Browser . requestIdleCallback ) {
9394 if ( deadline && deadline . timeRemaining ) {
9495 const t = deadline . timeRemaining ( ) ;
@@ -97,8 +98,16 @@ function frameLoop(deadline) {
9798 console . error ( 'idle timeout in' , idleTimeout ) ;
9899 }
99100 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+ }
102111 }
103112 }
104113 requestIdleCallback ( frameLoop , { timeout : idleTimeout } ) ;
0 commit comments