同步完整源码 - 2026-05-24
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Worker test</title>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
var worker = new Worker('worker.js');
|
||||
worker.onmessage = function(message) {
|
||||
console.log(message.data);
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,16 @@
|
||||
console.log('hello from the worker');
|
||||
|
||||
function workerFunction() {
|
||||
return 'worker function result';
|
||||
}
|
||||
|
||||
self.addEventListener('message', event => {
|
||||
console.log('got this data: ' + event.data);
|
||||
});
|
||||
|
||||
(async function() {
|
||||
while (true) {
|
||||
self.postMessage(workerFunction.toString());
|
||||
await new Promise(x => setTimeout(x, 100));
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user