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

Is there a problem with transferring binary objects by Worker? #5586

Closed
geeeger opened this issue May 18, 2020 · 2 comments
Closed

Is there a problem with transferring binary objects by Worker? #5586

geeeger opened this issue May 18, 2020 · 2 comments

Comments

@geeeger
Copy link

geeeger commented May 18, 2020

my issue:

// main.ts
worker.onmessage = async function (e: MessageEvent) {
    console.log(e.data)
}
// worker.ts
self.onmessage = async function (e) {
    // this.console.log(e.data)
    self.fetch(e.data.url, {
        headers: {
            range: e.data.range
        }
    }).then(res => (res.blob()))
    .then(res => res.arrayBuffer())
    // .then(res=> this.console.log(res))
    .then(res => self.postMessage(res))
    .catch(e => this.console.log(e))
}

then i got an [object Object] and it is not ArrayBuffer

if i use transfer list

i got an error:

error: Uncaught Error: TS2554 [ERROR]: Expected 1 arguments, but got 2.
    .then(res => self.postMessage(res, [res]))
                                       ~~~~~
    at file:///D:/works/deno/worker.ts:10:40
    at WorkerImpl.#poll ($deno$/web/workers.ts:198:17)
@geeeger
Copy link
Author

geeeger commented May 18, 2020

In addition, I set the deno option to true

@bartlomieju
Copy link
Member

Structured clone and transfer are not yet implemented: #3557

We should change the typing to allow transfer list and throw an error like in case of structured close.

@geeeger geeeger closed this as completed May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants