sqlite/sqlite-wasm

add sqlite-worker1-promiser.mjs

hikaruna opened this issue · 5 comments

this is request

promiser esm version.

thanks.

From the Promiser docs:

   Notable shortcomings:

   - This API was not designed with ES6 modules in mind. Neither Firefox
     nor Safari support, as of March 2023, the {type:"module"} flag to the
     Worker constructor, so that particular usage is not something we're going
     to target for the time being:

     https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker

PS: as its author, i discourage folks from using the Worker1/Promiser1 APIs for anything but the most basic of toy software. They have worker-related performance bottlenecks and it's next to impossible to properly manage transactions when accessing the sqlite API via a separate JS thread.

@sgbeal
Thanks for your prompt reply and advice.

I do however have a few questions.

It seems to me that whether or not the browser supports the {type: "module"} flag is irrelevant to the promiser code.

Since a worker can be injected when the promiser is generated, whether that worker is of type classic or module, doesn't the promiser just process the message?

If that is the case, then there would be no problem with publishing the promiser esm code.

Also, as of 2024/03, safari and firefox support the {type: "module"} flag.

i unfortunately don't remember the specifics of it but remember it not working back when we tried it a year ago. i will look into it again as energy allows, but am hesitant to make that a module because, quite frankly, people should not be using the worker1/promiser1 APIs except for toy applications, and making it a module would make it readily accessible to many users who otherwise will not touch it.

@hikaruna A new file, sqlite3-worker1-promiser.mjs now offers (A) loading the promiser as a module and (B) changes the use of an onload() handler in the promiser factory to a promise. The API change for (B) required a new interface, to avoid breaking older code, and is now called sqlite3Worker1Promiser.v2(). That's the version served by (A). This will be part of 3.46 and is currently available via a snapshot copy at:

https://sqlite.org/wasm/uv/snapshot.html

the docs on sqlite.org/wasm will be updated this evening to account for this feature.

That said: the worker1 API is still not recommended for use in anything but the most basic (or toy) apps because of the limitations its working model imposes (https://sqlite.org/wasm/doc/trunk/api-worker1.md).

Edit: the docs have been updated - see the link in the previous paragraph.