🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

idle-tasks

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

idle-tasks

The idle-tasks module is for optimization tasks which it can be running lazy. It may be useful for boost your page loading time.

latest
Source
npmnpm
Version
0.1.3
Version published
Maintainers
1
Created
Source

idle-tasks

Version Build Status code style: prettier Coverage Status npm bundle size Snyk Vulnerabilities for npm package dependencies Status

The common web apps use lot's of javascript today. The javascript on your web is not only own but also third party's. So you need define priority for better performance and some less important code evaluate lazy. The idle-tasks module allow you define queue of tasks which will be evaluated after browser is idle. It use requestIdleCallback under the hood. If requestIdleCallback was not support in browser it would use setTimeout.

Installation

npm i idle-tasks --save

Usage


import { createIdleQueue, Event } from 'idle-tasks';

function createTask() {
  return (deadline) => {
    return new Promise((resolve) => {
      setTimeout(resolve, 100 + time);
    })
  }
}

const idleQueue = createIdleQueue({
  ensureTasks: true,
  timeout: 1000
});

idleQueue.addTask(createTask());
idleQueue.addTask(createTask());
idleQueue.addTask(createTask());
idleQueue.addTask(createTask());
idleQueue.addTask(createTask());

idleQueue.on(Event.Start, () => console.log('start tasks'));
idleQueue.on(Event.Finish, ({ results }) => console.log('finish tasks', ...results));
idleQueue.on(Event.Error, ({ error }) => console.error(error));

// for running tasks immediately
// idleQueue.run();

// for scheduling tasks
idleQueue.schedule();

Keywords

idle

FAQs

Package last updated on 01 Jan 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