crxgames / threadpool-js

Basic Javascript thread pool implementation using web workers. For use with or without require.js.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

threadpool.js Bower version

threadpool.js is aimed to be a general-purpose multi-threading library for Javascript. It's key features are portability and ease of use. The library can either be used in a stand-alone fashion or as a require.js module.

Usage

You can add threadpool-js to your project using bower or just by adding this script tag:

<script type="text/javascript" src="http://andywer.github.io/threadpool-js/threadpool.min.js"></script>

Example use

Include the library at first. Just add the threadpool.js file to your project and include it per <script> tag. Alternatively you may use require.js.

// Init new threadpool with default size
var pool = new ThreadPool();

// Spawn two threads
pool.run(mythread, "Hello")
  .done(function(result) {
    document.write("Thread #1: " + result);
  });
pool.run(mythread, " World")
  .done(function(result) {
    document.write("Thread #2: " + result);
  });

// Hint: Keep in mind that you are free to use the done() and error() handlers
//       on single jobs and the whole pool!

// Thread logic
function mythread (param, done) {
  done( param.toUpperCase() );
}

Demo

Try the samples.

(Use Chrome, Firefox, IE, or Opera) Note: IE support experimental

License

This library is published under the MIT license. See LICENSE for details.

About

Basic Javascript thread pool implementation using web workers. For use with or without require.js.

License:MIT License


Languages

Language:JavaScript 100.0%