JSPM

request-idle-callback

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 158
  • Score
    100M100P100Q85340F
  • License MIT

Browser shim for window.requestIdleCallback

Package Exports

  • request-idle-callback

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (request-idle-callback) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Request Idle Callback Shim

For more information refer to Using requestIdleCallback

Install

npm install request-idle-callback

Example

var ric = require('request-idle-callback')
// Executes myNonEssentialWork duting idle time on each frame or fallbacks to using setTimeout to run at most 50ms per frame
ric.requestIdleCallback(myNonEssentialWork);

function myNonEssentialWork (deadline) {
  while (deadline.timeRemaining() > 0)
    doWorkIfNeeded();
}

API

requestIdleCallback(callback(deadline))

deadline is an object containing:

  • deadline.didTimeout boolean indicating if it is still time to deadline.
  • deadline.timeRemaining function that returns remaining time.

cancelIdleCallback(id)

Removes callback from the queue or calls clearTimeout.

Tests

node tests.js

Licencia

MIT