ric
request-idle-callback
npm i request-idle-callback
ric

request-idle-callback

Browser shim for window.requestIdleCallback (https://developers.google.com/web/updates/2015/08/using-requestidlecallback)

by Santiago Gil

1.0.2 (see all)License:MITTypeScript:Not Found
npm i request-idle-callback
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

Downloads/wk

1.1K

GitHub Stars

26

LAST COMMIT

6yrs ago

MAINTAINERS

1

CONTRIBUTORS

0

OPEN ISSUES

3

OPEN PRs

1
VersionTagPublished
1.0.2
latest
6yrs ago
No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate