Socket
Socket
Sign inDemoInstall

@horat1us/request-idle-callback

Package Overview
Dependencies
13
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @horat1us/request-idle-callback

Request Idle Callback Polyfill


Version published
Weekly downloads
78
decreased by-62.32%
Maintainers
1
Install size
257 kB
Created
Weekly downloads
 

Readme

Source

IdleCallback

Available as commonjs and esm module with typescript typings.
See Using requestIdleCallback for details.

This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the spec.

Includes TypeScript typings and source code.

Installation

Using npm:

npm i @horat1us/request-idle-callback

Usage

Most common usage:


var handler = require('@horat1us/request-idle-callback')();
	/* or */
handler = require('@horat1us/request-idle-callback/polyfill')(); 

// returns native requestIdleCallback/cancelIdleCallback if compliant
handler.requestIdleCallback;
handler.cancelIdleCallback;

ESM module also available:

import { requestIdleCallback, cancelIdleCallback } from "@horat1us/request-idle-callback"

To shim (replace global) you need to use:

require("@horat1us/request-idle-callback").shim();
// or
require("@horat1us/request-idle-callback/auto");

Or ESM (prefered):

import {shim} from "@horat1us/request-idle-callback/esm";
shim();

IdlePromise

You can also use IdlePromise.
Note: Promise support in runtime environment is required

import { IdlePromise, IdlePromiseCancel } from "./src/IdlePromise";

// Create Promise
const promise = IdlePromise({
    timeout: 5000,
});

// Process event, handle rejections
promise
    .then((deadline) => {
        // resolved, same as requestIdleCallback
        console.log(deadline)
    })
    .catch((error) => {
        if (error.message === "Idle Promise Cancel") {
            // handle cancellation
            return;
        }
        // handle rejection
    });

// You can also cancel idleCallack resolving
promise.cancel("Some Reason");

License

MIT

Keywords

FAQs

Last updated on 18 Sep 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc