GoogleChromeLabs / GoogleChromeLabs/comlink

Web Worker Hangs if Imported File Contains Top-Level `Await`

Open
#635 6 comments 5 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
12.8k
Forks
435
PR merge metrics
No merged PRs in 30d

Description

Whatever your thoughts are on top-level await, I'm initializing a library using `await`. However, the web worker seems to hang once it encounters the `await`, preventing the rest of the web worker from executing. Any imported file with a top-level await causes this.

I've made a [reproducible example](https://codesandbox.io/p/sandbox/silly-sun-hz4zsj) (make sure to use a Chromium browser). If the `count is {count}` button is clicked, the `getNumberPlusOne` function in `fakeTopLevelAwait` won't work. If the await is commented out, `getNumberPlusOne` executes successfully.

I'd like to know if this a limitation in Web Workers or comlink. I'd really like to get this working. And kudos on such a fantastic lib!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.