JavaScriptã§ãã«ãã¹ã¬ãã(navigator.newWorkerPool)
437152 – implement worker threadsã使ã£ã¦ã¿ãã
var thread = navigator.newWorkerPool(); thread.createWorker(function(){ setTimeout( clearInterval, 1000, setInterval(postMessageToPool, 5, "thread1")); }.toSource() + "()"); thread.createWorker(function(){ setTimeout( clearInterval, 1000, setInterval(postMessageToPool, 5, "thread2")); }.toSource() + "()"); thread.messageListener = function(message){ console.log(message); };
thread1, thread2, thread2, thread2, thread2, thread1, thread1, thread1, thread1, thread2, thread1, thread2 ...
ã¨ãã£ãæãã«ãJavaScriptããã«ãã¹ã¬ããã§åãã¦ãã
æ°ãä»ãããã¨ã¯ãcreateWorkerã«ã¯æååã渡ããã¨ãcreateWorkerã®ä¸ã§ã¯XMLHttpRequestã¨ãdocumentã¨ãã«è§¦ããªããã¨ãã¹ã¬ããã»ã¼ããªXHRã¯ãã¾ã å®è£
ããã¦ãªãã
ã¹ã¬ããã¨ã®ããåãã¯ãpostMessage()ã¨ãmessageListenerã¨ãpostMessageToPoolã使ããæååã®ã¿ãªã®ã§ãJSONã使ã£ããããã
JavaScriptã§éãå¦çããããã¨ã¯ãã¾ãç¡ããããã©ããã£ãæã«ã¹ã¬ããã使ãã¹ããªã®ãã¾ã åãã£ã¦ãªãã
åè:DOMWorkerThreads current - MozillaWiki