Thread and ThreadPool functions.
npm install uupaa.thread.js
Thread and ThreadPool functions.
This module made of WebModule.
``js
// main.html
var thread = new WebModule.Thread("worker.js", function postMessageHandler(args) {
;
}, function(exitCode) {
switch (exitCode) {
case Thread.EXIT_OK: console.log("Closed."); break;
case Thread.EXIT_ERROR: console.log("Terminates with an error from WorkerThread. " + errorMessage); break;
case Thread.EXIT_FORCE: console.log("Forced termination by user."); break;
case Thread.EXIT_TIMEOUT: console.log("Watchdog barked.");
}
});
thread.post(["HELLO", 123], null, function postbackMessageHandler(args) {
console.log(args[0]); // "HELLO WORLD"
thread.close();
});
`
`js
// worker.js
importScripts("
importScripts("
var thread = new WebModule.ThreadProxy(function postMessageHandler(args, event) {
console.log(args[0]); // "HELLO"
console.log(args[1]); // 123
event.postback(args[0] + " WORLD"); // call to postbackMessageHandler
}, function closeRequestHandler(yes, ng) {
// .... destruction process...
yes(); // -> closed as usual.
});
``