Skip to content

tjaehnel/simplejstaskscheduler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple JavaScript Task Scheduler

The aim of this small JavaScript class is to serialize asynchronious JavaScript tasks such as AJAX requests, timers. Simply enqueue your task and notify the system when it's finished.

Example to run two timers sequentially:

// prepare two tasks to run
var runAfter3s = function(taskHandle) {
  window.setTimeout(function() {
    alert("Hit first timeout");
    // important to notify the scheduler about completion
    tm.asyncTaskFinished(taskHandle);
  }, 3000);
};
var runAfter5s = function(taskHandle) {
  window.setTimeout(function() {
    alert("Hit second timeout");
    tm.asyncTaskFinished(taskHandle);
  }, 5000);
};

// get an instance of the scheduler and enqueue the tasks
var tm = new SimpleJsTaskScheduler();
tm.enqueueAsyncTask(runAfter3s);
tm.enqueueAsyncTask(runAfter5s);

// ... the two tasks are now run sequentially ...

You can also provide the enqueueAsyncTask method with callback functions to to be executed upon start and completion of the task. For more information see the source code documentation.

About

JavaScript Task Scheduler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published