background-tasks-api

1.1.5 • Public • Published

bta

Execute background tasks on main thread's idle periods

Task scheduler api which executes given tasks during main thread's idle periods by using window.requestIdleCallback method. As long as tasks exists, each will be scheduled for the next idle period.

Installation

npm install background-tasks-api --save

Usage

Import scheduleTasks from 'background-tasks-api';

var nonEssentialWork1 = () => {/* do something */};
var nonEssentialWork2 = () => {/* do something */};
var tasks = [ nonEssentialWork1, nonEssentialWork2 ];
var isFIFO = false;

scheduleTasks(tasks, isFIFO);

API

background-tasks-api accepts two parameters:

  • tasks: An array of functions which are going to be executed on main thread's idle periods.
  • isFIFO: A boolean to decide task execution order. Defaults to false.

Notes

In order to use it efficiently, it is crucial to have multiple small partitioned tasks, instead of long-running ones as each idle period has at most 50ms deadlines. Tasks will be executed in Last In First Out order by default.

License

Licensed under the MIT License, Copyright © 2019-present.

See LICENSE for more information.

Readme

Keywords

none

Package Sidebar

Install

npm i background-tasks-api

Weekly Downloads

3

Version

1.1.5

License

MIT

Unpacked Size

12.1 kB

Total Files

10

Last publish

Collaborators

  • alisait