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.
npm install background-tasks-api --save
Import scheduleTasks from 'background-tasks-api';
var nonEssentialWork1 = () => {/* do something */};
var nonEssentialWork2 = () => {/* do something */};
var tasks = [ nonEssentialWork1, nonEssentialWork2 ];
var isFIFO = false;
scheduleTasks(tasks, isFIFO);
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.
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.
Licensed under the MIT License, Copyright © 2019-present.
See LICENSE for more information.