mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-11 01:42:22 +03:00
Initial bits for a JS API variant in which the client operates in the main thread and sqlite3 in a Worker. This is far from complete.
FossilOrigin-Name: f6d6f969791f0d2367ae5418623b4794f6df657d9d7d9002fb5aec4206dcfd4c
This commit is contained in:
43
ext/fiddle/testing2.js
Normal file
43
ext/fiddle/testing2.js
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
2022-05-22
|
||||
|
||||
The author disclaims copyright to this source code. In place of a
|
||||
legal notice, here is a blessing:
|
||||
|
||||
* May you do good and not evil.
|
||||
* May you find forgiveness for yourself and forgive others.
|
||||
* May you share freely, never taking more than you give.
|
||||
|
||||
***********************************************************************
|
||||
|
||||
A basic test script for sqlite3-worker.js.
|
||||
*/
|
||||
(function(){
|
||||
/** Posts a worker message as {type:type, data:data}. */
|
||||
const SW = new Worker("sqlite3-worker.js");
|
||||
const wMsg = (type,data)=>SW.postMessage({type, data});
|
||||
const log = console.log.bind(console);
|
||||
const warn = console.warn.bind(console);
|
||||
SW.onmessage = function(ev){
|
||||
if(!ev.data || 'object'!==typeof ev.data){
|
||||
warn("Unknown sqlite3-worker message type:",ev);
|
||||
return;
|
||||
}
|
||||
ev = ev.data/*expecting a nested object*/;
|
||||
switch(ev.type){
|
||||
case 'sqlite3-api':
|
||||
switch(ev.data){
|
||||
case 'loaded':
|
||||
log("Message:",ev); return;
|
||||
case 'ready':
|
||||
log("Message:",ev);
|
||||
self.sqlite3TestModule.setStatus(null);
|
||||
return;
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
warn("Unknown sqlite3-api message type:",ev);
|
||||
};
|
||||
log("Init complete, but async bits may still be running.");
|
||||
})();
|
||||
Reference in New Issue
Block a user