Code Monkey home page Code Monkey logo

threadpool-js's Introduction

threadpool.js npm version 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() );
}

Support for transferable objects

If you want to pass large blobs to your workers efficiently, you may use a feature called transferable objects.

threadpool-js supports them. Just pass the array of buffers to transfer (after the worker parameter) to the pool's run method:

pool.run(mythread, {hash: "sha512", data: myUint8Array}, [myUint8Array.buffer]);

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.

threadpool-js's People

Contributors

andywer avatar crxgames avatar devongovett avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.