Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8b49a1e

Browse files
web workers
1 parent c3c5b8c commit 8b49a1e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,3 +1005,20 @@ oldnode.parentNode.replaceChild(clone, oldNode);
10051005
* can reduce the number of event listeners by attaching one only to the parent
10061006
* event properties can be used to filter out the events we care about
10071007
* drawback: slightly more complex code but there are JS libraries to make this easy
1008+
1009+
### web workers
1010+
1011+
* javascript runs on a single thread in the browser
1012+
* web workers: background thread support by the browser
1013+
* only in modern browsers
1014+
* you put worker code in a separate file
1015+
* worker can use ```postMessage``` to send messages to the caller
1016+
* caller can subscribe to messages using ```Worker.onMessage```
1017+
1018+
```js
1019+
var worker = new Worker('my_worker.js');
1020+
worker.onMessage(function(event) {
1021+
console.log(event.data);
1022+
});
1023+
//my_worker.js: postMessage('hello there');
1024+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /