- index.html
- webworkers.js
- task.js
- smserver.js
Last active
June 19, 2017 00:12
-
-
Save rpragana/b7c440fc9b3abdd882e64a595dbda75d to your computer and use it in GitHub Desktop.
Web Workers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> <meta charset="utf-8"> </head> | |
<body> | |
<a href="javascript:sendMsg()">send msg</a> | |
<p id="log"></p> | |
<script> | |
var worker = new Worker('task.js'); | |
worker.addEventListener('message', function(e) { | |
document.getElementById('log').innerHTML += | |
'O web worker respondeu: '+e.data+'<br />'; | |
}, false); | |
var n=1; | |
function sendMsg() { | |
worker.postMessage(n++ +': testando...'); | |
} | |
worker.postMessage('Olá, Web Worker!'); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env nodemon | |
var express = require('express'); | |
var app = express() | |
app.use(express.static(__dirname + '/')); | |
app.listen(8000); | |
console.log('Aponte seu navegador para http://localhost:8000/'); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.addEventListener('message', function(e) { | |
self.postMessage("Recebi: "+e.data); | |
}, false); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var worker = new Worker('task.js'); | |
worker.addEventListener('message', function(e) { | |
console.log('Worker said: ', e.data); | |
}, false); | |
var n=1; | |
function sendMsg() { | |
worker.postMessage(n++ +': testando...'); | |
} | |
worker.postMessage('Hello World'); // Send data to our worker. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment