aboutsummaryrefslogtreecommitdiff
path: root/ext/fiddle/testing2.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-06-01 00:00:59 +0000
committerstephan <stephan@noemail.net>2022-06-01 00:00:59 +0000
commitbff17db433d1b0240a9e40a7f33e7a873f9cec71 (patch)
tree7a52d6de1dfaf8b806c744245a060b7e52e367f5 /ext/fiddle/testing2.js
parentc7fc08f69accd7bb3753477df503660ecacf2e81 (diff)
downloadsqlite-bff17db433d1b0240a9e40a7f33e7a873f9cec71.tar.gz
sqlite-bff17db433d1b0240a9e40a7f33e7a873f9cec71.zip
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
Diffstat (limited to 'ext/fiddle/testing2.js')
-rw-r--r--ext/fiddle/testing2.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/ext/fiddle/testing2.js b/ext/fiddle/testing2.js
new file mode 100644
index 000000000..c25885425
--- /dev/null
+++ b/ext/fiddle/testing2.js
@@ -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.");
+})();