-
Notifications
You must be signed in to change notification settings - Fork 2
API Document
var thread = new Thread(function(){
return "hello thread.js";
});
thread.once().done(function(res){
console.log(res); // -> hello thread.js
});new Thread(func, [depends])
| arguments | description |
|---|---|
| func | run by calling execute () or once (). |
| [depends] | Dependent libraries as Array or String |
new Thread(function(a, b){
return a + b;
})thread.once(args1, args2, ...)
Run the function passed by the constructor.
This is done only once, after which the object is terminated.
| arguments | description |
|---|---|
| args | Arguments passed to the function. |
thread.once(1, 2);thread.execute(args1, args2, ...)
Run the function passed by the constructor.
Usually, please use once().
| arguments | description |
|---|---|
| args | Arguments passed to the function. |
thread.execute(1, 2);thread.terminate()
Instantly terminate the Thread object. Even if a thread is processing it, it forcibly unloads from memory.
| arguments | description |
|---|---|
| (no arguments) | (no description) |
thread.terminate();thread.done(func)
thread.fail(func)
thread.always(func)
A method that defines the behavior of processing success (done), failure (fail), and always.
The function is stored in the queue, and when one of the above events is issued, it is called in the order in which it was set.
| arguments | description |
|---|---|
| func | Function called upon completion of processing. |
thread.done(function(res){
console.log(res);
});thread.progress(func)
Called by the notify method in the local scope of the function passed to the constructor.
| arguments | description |
|---|---|
| func | Function called upon notify() method. |
var thread = new Thread(function(){
for(var i = 0; i <= 100; i++){
for(var j = 0; j < 10000000; j++){
// .. Very slow processing
}
notify(i);
}
});
thread.once().progress(function(i){
console.log(i);
}).done(function(){
console.log("done!");
});