View on GitHub

Threadpool.js

Light ThreadPool Library to Javascript

Download this project as a .zip file Download this project as a tar.gz file

Light Task Queue in Javascript

This is a light threadpool library to javascript. In this threadpool you can set a priority for each task and change dynamically. Furthermore, you can also define the thread pool size.

Example

var threadpool = new ThreadPool(2);

function myTask(number)
{
    // Execute myStaff 
    console.log("This is my Task, n " + number);
    // Set this taskl to be completed. 
    this.complete();
}

threadpool.run(new Runnable(myTask, 1, 1));
threadpool.run(new Runnable(myTask, 1, 2));
threadpool.run(new Runnable(myTask, 1, 3));
var runnable = new Runnable(myTask, 1, 4);
threadpool.run(runnable);
threadpool.run(new Runnable(myTask, 1, 5));
runnable.setPriority(0); // burst priority 
threadpool.run(new Runnable(myTask, 1, 6));
threadpool.destroy();

Demos/Examples

Similar projects

Authors

License

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.