https://github.com/sourcepirate/worker.js
https://github.com/sourcepirate/worker.js
Last synced: 17 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/sourcepirate/worker.js
- Owner: sourcepirate
- Created: 2015-09-24T06:35:49.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-09-24T06:40:32.000Z (over 10 years ago)
- Last Synced: 2024-04-14T07:20:18.485Z (about 2 years ago)
- Language: JavaScript
- Size: 125 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
##Thread.js
Theading Implementation using HTML5 WorkerAPI.
##Installation
```
#through npm
git clone https://github.com/plasmashadow/worker.js
cd worker.js/
npm install
#on browser
```
##Usage
###Creating Threads
```javascript
var thread = new Thread();
var childid = thread.addTask(function(a){
for(var i=0; i< 100; i++){
cosole.log(a);
}
}, "sathya");
var childid2 = thread.addTask(function(a){
for(var i=0; i< 100; i++){
cosole.log(a);
}
}, "adhi");
thread.start();
```
###Event handling
Thread Events can be managed by their respective events.
```javascript
var thread = new Thread();
thread.once('message', function(message){
console.log(message);
})
thread.once('close', function(){
console.log("thread is ending");
})
thread.once('error', function(error){
console.log(error);
})
```
###Posting Message to Child Threads
Posting message can to the childs can be done with there childids.
```javascript
thread.message(childid, "please work fast");
```
##License
MIT