Tasker - globules-io/OGX.JS GitHub Wiki

Starting at version 1.38, OGX.JS supports background tasks. OGX.Tasker is built as a static class. Note that you can also use Workers to achieve the same result.

This is based on the request requestIdlecallback feature of the browser. The task list will run when the idle callback is fired. There is an option to only run the tasks if the tab is blured.

Keep in mind that, no matter what, the browser will change the interval at which the background tasks can run to 5 minutes after the tab has been blured. The background task will run at best at least every 5 minutes from this point on.

Methods

 OGX.Tasker.add(_ID_, _FUNCTION_, _PARAMS_, _RECURRING_, _BLUR_ONLY_);
 OGX.Tasker.remove(_ID_); 

Run a background task once

OGX.Tasker.add('test', () => {console.log('I ran!');});

Run a background task once with parameters

OGX.Tasker.add('test', (msg) => {console.log(msg);}, 'I ran');

Run a recurring background task with parameters every 2 minutes

OGX.Tasker.add('test', (msg) => {console.log(msg);}, 'I ran', 2 * 60 * 1000);

The task will run every 2 minutes until the tab is blured, then every 5 minutes.

Run a recurring background task with parameters every 2 minutes when the tab is blured

OGX.Tasker.add('test', (msg) => {console.log(msg);}, 'I ran', 2 * 60 * 1000, true);

Remove a task

OGX.Tasker.remove('test');