Background task

An simple function wrapper around requestIdleCallback that queues tasks and runs them sequentially.

The main purpose is to be able to run maintainance functions that are not a good fit for a web worker context (i.e. methods that require the DOM).

Usage

Wrap your function.

const task = backgroundTask(() => {
	// do stuff
});

task().then(result => {
	// task has finished.
});

Call task as you would any other async function. The return value is a promise for when the background task completes.

Calling a task multiple times will queue the passed parameters and execute the task sequentially the same number of times.

Description
BackgroundTask is a function wrapper to run maintenance routines in the DOM thread when there is available time.
Readme 160 KiB
Languages
JavaScript 100%