0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jsでマルチスレッド的にループを回す

Posted at

マルチスレッド的にループを回す

worker.js
self.addEventListener('message', (message) => {
    for (let index = 0; index < 100; index++) {
        console.log(message.data + "_" + index);
        
    }
});
実行側
// メッセージを送信する
const worker1 = new Worker('worker.js');
worker1.postMessage('こんにちは1');
const worker2 = new Worker('worker.js');
worker2.postMessage('こんにちは2');
const worker3 = new Worker('worker.js');
worker3.postMessage('こんにちは3');

これでこんにちはが入り乱れて実行される。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?