Is it possible to use transferable objects in Kotl...
# javascript
d
Is it possible to use transferable objects in Kotlin/JS? It looks like it uses a strange square-bracket syntax that I'm not sure how to emulate in Kotlin. https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Transferable_objects
Copy code
const uInt8Array = new Uint8Array(1024 * 1024 * 8).map((v, i) => i);
console.log(uInt8Array.byteLength); // 8388608
worker.postMessage(uInt8Array, [uInt8Array.buffer]);
console.log(uInt8Array.byteLength); // 0
r
Isn't it just an array?
d
Oh is that what that's doing?
although it's still weird it's posting both the array itself and the buffer as an array?
Sorry I was overthinking it
r
https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage#transfer Those can be other objects as well and there may be more than one.
d
Seems like postMessage takes a list of transferable objects, so here it's a list of one
Right exactly
Sorry for the dumb question. I thought for a bit there was some magical syntax for transferable objects 😄
t
although it's still weird it's posting both the array itself and the buffer as an array?
It's an option, you can "transfer" buffer, or don't transfer