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

Seems to not really use microtasks inside a Web Worker #27

Open
dumbmatter opened this issue Mar 7, 2017 · 5 comments
Open

Seems to not really use microtasks inside a Web Worker #27

dumbmatter opened this issue Mar 7, 2017 · 5 comments

Comments

@dumbmatter
Copy link

I'm trying to use Promises with IndexedDB inside a Web Worker. Outside of a Web Worker, I know this is tricky... native promises work in Chrome, but in Firefox you need a polyfill that correctly uses microtasks, such as your lie library which relies on this project for queuing microtasks.

That works fine, except inside a Web Worker there is no MutationObserver so you need to use other tricks. That seems to not play nice with IndexedDB transactions. Here's an example. Run npm start, go to the URLs it tells you to, and look in the console. You'll see that the same simple IndexedDB code works when required directly in the browser, but fails in a worker. Inside the worker, it closes the transaction before it runs the callback of the immediate function.

Can you think of any possible solution to this problem besides synchronous promise resolution?

@dumbmatter
Copy link
Author

Also, I posted the same question on Stack Overflow http://stackoverflow.com/questions/42660581/microtasks-inside-web-workers so if you know the answer, you can get some free Internet points too :)

@calvinmetcalf
Copy link
Owner

calvinmetcalf commented Mar 8, 2017 via email

@dumbmatter
Copy link
Author

It's using MessageChannel currently, and it looks like it has been that way for a while.

@calvinmetcalf
Copy link
Owner

answered on stack exchange but basically there isn't a good way to do microtasks in a web worker, but the real issue is that promises and IDB arn't in sync re tasks I've reached out to some people on twitter who are likely to be in the know so we can see what they have to say.

@calvinmetcalf
Copy link
Owner

ok so there is this article and this issue dexie/Dexie.js#317

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