* Run a task. * Schedule the next round if there are more tasks. * @param {?IdleDeadline} idleDeadline * @return {boolean} Whether anything was executed. * @private
(idleDeadline)
| 397 | * @private |
| 398 | */ |
| 399 | execute_(idleDeadline) { |
| 400 | const t = this.nextTask_(/* opt_dequeue */ true); |
| 401 | if (!t) { |
| 402 | this.scheduledImmediateInvocation_ = false; |
| 403 | this.durationOfLastExecution_ = 0; |
| 404 | return false; |
| 405 | } |
| 406 | let before; |
| 407 | try { |
| 408 | before = Date.now(); |
| 409 | t.runTask_(idleDeadline); |
| 410 | } finally { |
| 411 | // We want to capture the time of the entire task duration including |
| 412 | // scheduled immediate (from resolved promises) micro tasks. |
| 413 | // Lacking a better way to do this we just scheduled 10 nested |
| 414 | // micro tasks. |
| 415 | resolved |
| 416 | .then() |
| 417 | .then() |
| 418 | .then() |
| 419 | .then() |
| 420 | .then() |
| 421 | .then() |
| 422 | .then() |
| 423 | .then() |
| 424 | .then(() => { |
| 425 | this.scheduledImmediateInvocation_ = false; |
| 426 | this.durationOfLastExecution_ += Date.now() - before; |
| 427 | dev().fine( |
| 428 | TAG, |
| 429 | t.getName_(), |
| 430 | 'Chunk duration', |
| 431 | Date.now() - before, |
| 432 | this.durationOfLastExecution_ |
| 433 | ); |
| 434 | |
| 435 | this.schedule_(); |
| 436 | }); |
| 437 | } |
| 438 | return true; |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * Calls `execute_()` asynchronously. |