Coder Social home page Coder Social logo

webrtcgame / thread.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from supersoaker/thread.js

0.0 2.0 0.0 339 KB

javascript plugin allows to execute any function of javascript code in a thread

License: MIT License

JavaScript 86.57% HTML 13.43%

thread.js's Introduction

Thread.js

is a javascript plugin, which allows you to execute any function of a your code in a thread.

Standalone function: simply pass it as an argument to the Thread(), and get the result in a callback function. You don't need to create a separate file for each thread, like you normally do with a regular worker.

Object's method: Thread accepts context as an optional parameter and executes function in its context. Simply pass the object as a context, that's it.

Function with dependencies: Thread accepts a list of file names as an optional argument and imports these files in the thread before the function is calling

In main page you execute it this way:

function sum(num1, num2) {
    return num1 + num2;
}

var foo = sum(2,3);
console.log(foo);

Now, let's open a new thread and execute function sum() in this thread.

function sum(num1, num2) {
    return num1 + num2;
}

Thread.exec(
  sum,                // function to execute in a thread
  [2,3],              // arguments for the function
  function(data){     // callback function to process result
  	var foo = data;
  	console.log(foo);
  }
);

See live examples at http://eslinstructor.net/vkthread

Thread.js is built on HTML5 "Worker" technology. It also incorporates JSONfn code to implement the key tasks. In spite of technical complexity, plugin is super compact. Development version (plain text with comments) is less than 2k. I don't care to minifiy it.

thread.js's People

Contributors

vkiryukhin avatar webrtcgame avatar supersoaker avatar

Watchers

James Cloos 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.