Skip to content

alisaitbilgi/background-tasks-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Execute background tasks on main thread's idle periods

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published