IndexedDB synchronous api + web workers - what's the point?

The indexed DB syncronous API file is intended for use inside a web worker :

The synchronous API is intended for use only within web workers.

But since theres ansyncronous API, then why use a synchronous API in a web worker. Does the asynchronous API not affect the user interface thread at all?

+4
source share
3 answers

The synchronous API has not yet been implemented in any browser, and it is marked as a dangerous part of the IndexedDB standard and can be removed. And currently, only Google Chrome has implemented IndexedDB access inside web workers using async api.

Links W3C , Mozilla :

The following features are at risk and may be removed due to a potential lack of implementations.

+2
source

The synchronous API is easier to use, then the asynchronous API. Async is not needed by the web worker.

+8
source

After you think it is necessary to work asynchronously in a web worker and even think that a good idea in the synchronization API for a background thread seems to be a terrible trap.

The fact is that synchronization is a fake for waiting for I / O. Regardless of whether they are asynchronous or synchronized, internally they are one and the same process of asynchronous operation . The worker should do interesting CPU work while waiting for I / O.

Moreover, we may already have asynchronous code for the user interface thread. Reusing asynchronous code is better than coding async for the foreground and synchronization for the background.

The Async API can create multiple transactions using different capabilities and modes. These asynchronous transaction flows alternate. Unable to rotate transactions in the synchronization API.

The only advantage we get in the synchronization API is easy to use. But an asynchronous workflow using a perspective / deferred template is already well understood.

Perhaps a good synchronization API is the process of scanning the cursor (also for the user interface thread), since it does not involve serialization and probably does not require I / O. However, IDBCursor for the synchronization API and IDBCursorWithValue for the asynchronous API will be confused, although the use cases are different.

A truly great idea for the synchronization API is a terrible trap for developers writing a high-performance program.

+3
source

Source: https://habr.com/ru/post/1432146/


All Articles