New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

raf-thenable

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

raf-thenable

requestAnimationFrame wrapper to PromiseLike interface

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

raf-thenable

requestAnimationFrame wrapper to PromiseLike interface

Example

import rafThenable from 'raf-thenable';

// basic usage
const p = rafThenable(now => {
  // draw canvas or do same animation
  // it executed directly in the animation frame (before rendering)
  console.log(now); // now is time like performance.now()
});

setTimeout(() => {
    // it's cancel animation frame and rejects promise in p
    p.cancel();

    // if you don't want to reject p, pass true to cancel
    p.cancel(true);
}, 0);

// p is normal Promise from your global scope (window object)
// you can await it or call any promise instance method
const now = await p;
p.then(now => { /* ... */ }).then(/* ... */);
p.catch(() => { /* Oops, canceled without true parameter */ });
p.finally(() => { /* ... */ });

// rafThenable implements PromiseLike interface (then method)
// you can await it or return from then callback
// but it will be executed in microtask (after animation frame and after rendering)
const now = await rafThenable;
otherPromise.then(() => {
    /* ... */
    return rafThenable;
}).then(now => { /* ... */ });

Keywords

requestAnimationFrame

FAQs

Package last updated on 22 Dec 2020

Did you know?

Socket

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