JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 20
  • Score
    100M100P100Q61138F
  • License MIT

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

Package Exports

  • idle-tasks

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (idle-tasks) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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();