ric.js 526 B

12345678910111213141516171819202122
  1. var root = require('./root');
  2. var now = require('./now');
  3. exports =
  4. root.requestIdleCallback ||
  5. function(cb) {
  6. var start = now();
  7. return setTimeout(function() {
  8. cb({
  9. didTimeout: false,
  10. timeRemaining: function() {
  11. return Math.max(0, 50 - (now() - start));
  12. }
  13. });
  14. }, 1);
  15. };
  16. exports.cancel =
  17. root.cancelIdleCallback ||
  18. function(id) {
  19. clearTimeout(id);
  20. };
  21. module.exports = exports;