promise-worker | Promise-based messaging for Web Workers and Service Workers | Web Framework library
kandi X-RAY | promise-worker Summary
kandi X-RAY | promise-worker Summary
promise-worker
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of promise-worker
promise-worker Key Features
promise-worker Examples and Code Snippets
Community Discussions
Trending Discussions on promise-worker
QUESTION
The distinction between tasks and microtasks is important because IndexedDB transactions commit across tasks, but not microtasks. This is problematic when wrapping IndexedDB code in Promises, because in Firefox (and maybe other browsers), promise resolution does not happen in a microtask, so your transaction will commit.
The solution to this problem is to use a third-party promise implementation that uses microtasks. lie
is one of those libraries, and under the hood it abstracts the microtask problem into another library called immediate
, which uses MutationObserver
to generate microtasks.
That works great, most of the time. But in a Web Worker, MutationObserver
doesn't exist, so that trick won't work. Here's an example of the problem in an easily-runnable GitHub repo. Basically I have this code:
ANSWER
Answered 2017-Mar-13 at 12:35short answer: you can't do that in a web worker
long answer: there is no actual microtask api, there are just hacks to try to simulate them. Unfortunately the ones that work best (mutation observer,) mainly have to do with the DOM so they are only available in the main thread not in a web worker. That being said it may make sense for IDB and promises to standardize an official relationship, I'm not sure if there actually is one speced out as promises and IDB are from different groups. There actually might be some traction from browser vendors about doing a real microtask api inside of web workers as most of the objections have to do with accidentally hosing the main thread.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install promise-worker
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page