Last active
February 21, 2020 12:22
-
-
Save RReverser/1c9f9b252ab7b5e85e404dcbef261cd9 to your computer and use it in GitHub Desktop.
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
// Create a Worker we want to share memory with: | |
let w = new Worker(`data:text/javascript, | |
onmessage = ({data: memory}) => { | |
// Got WebAssembly.Memory once, log same instance forever with no further postMessages: | |
setInterval(() => console.log('Current buffer in worker:', memory.buffer), 5_000); | |
} | |
`); | |
// Create a shared growable memory: | |
let m = new WebAssembly.Memory({ initial:1, maximum: 65536, shared: true }); | |
// Send memory to the worker: | |
w.postMessage(m); | |
// ... within 5 seconds you should see SharedArrayBuffer(65536) in the console, coming from the Worker | |
// Now, let's grow memory by one page from the main thread: | |
m.grow(1); | |
// ... within 5 seconds you should see SharedArrayBuffer(131072) in the console | |
// This demonstrates that the previously shared memory object auto-updates on growth. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment