Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify what Transferable objects are #4

Open
JordanMartinez opened this issue Jan 11, 2023 · 4 comments
Open

Specify what Transferable objects are #4

JordanMartinez opened this issue Jan 11, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@JordanMartinez
Copy link
Contributor

Description

Replace Transferable opaque type with type class based on: https://html.spec.whatwg.org/multipage/structured-data.html#transferable-objects

@JordanMartinez JordanMartinez added the enhancement New feature or request label Jan 11, 2023
@gbagan
Copy link
Collaborator

gbagan commented Jan 11, 2023

A related issue is that ArrayBuffer are transferable and a transfer sets the byteLength to 0.
Thus the signature of byteLength must be

byteLength :: ArrayBuffer -> Effect ByteLength

https://pursuit.purescript.org/packages/purescript-arraybuffer/13.1.1/docs/Data.ArrayBuffer.ArrayBuffer

@JordanMartinez
Copy link
Contributor Author

A related issue is that ArrayBuffer are transferable and a transfer sets the byteLength to 0.

Where does the spec say that?

@gbagan
Copy link
Collaborator

gbagan commented Jan 12, 2023

https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Transferable_objects
In the first example:

// Create an 8MB "file" and fill it. 8MB = 1024 * 1024 * 8 B
const uInt8Array = new Uint8Array(1024 * 1024 * 8).map((v, i) => i);
console.log(uInt8Array.byteLength); // 8388608

// Transfer the underlying buffer to a worker
worker.postMessage(uInt8Array, [uInt8Array.buffer]);
console.log(uInt8Array.byteLength); // 0

The example is for uInt8Array but it is also true for ArrayBuffer.

@JordanMartinez
Copy link
Contributor Author

😭

Well that throws a wrench into things...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants