4 The author disclaims copyright to this source code. In place of a
5 legal notice, here is a blessing:
7 * May you do good and not evil.
8 * May you find forgiveness for yourself and forgive others.
9 * May you share freely, never taking more than you give.
11 ***********************************************************************
13 This is a JS Worker file for the main sqlite3 api. It loads
14 sqlite3.js, initializes the module, and postMessage()'s a message
15 after the module is initialized:
17 {type: 'sqlite3-api', data: 'ready'}
19 This seemingly superfluous level of indirection is necessary when
20 loading sqlite3.js via a Worker. Loading sqlite3.js from the main
21 window thread elides the Worker-specific API. Instantiating a worker
22 with new Worker("sqlite.js") will not (cannot) call
23 initSqlite3Module() to initialize the module due to a
24 timing/order-of-operations conflict (and that symbol is not exported
25 in a way that a Worker loading it that way can see it). Thus JS
26 code wanting to load the sqlite3 Worker-specific API needs to pass
27 _this_ file (or equivalent) to the Worker constructor and then
28 listen for an event in the form shown above in order to know when
29 the module has completed initialization. sqlite3.js will fire a
30 similar event, with data:'loaded' as the final step in its loading
31 process. Whether or not we _really_ need both 'loaded' and 'ready'
32 events is unclear, but they are currently separate events primarily
33 for the sake of clarity in the timing of when it's okay to use the
34 loaded module. At the time the 'loaded' event is fired, it's
35 possible (but unknown and unknowable) that the emscripten-generated
36 module-setup infrastructure still has work to do. Thus it is
37 hypothesized that client code is better off waiting for the 'ready'
38 even before using the API.
41 importScripts('sqlite3.js');
42 initSqlite3Module().then(function(){
43 setTimeout(()=>self
.postMessage({type
:'sqlite3-api',data
:'ready'}), 0);