]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Initial work at getting sqlite3Worker1Promiser.v2() to return a Promise instead of...
authorstephan <stephan@noemail.net>
Thu, 7 Mar 2024 16:04:43 +0000 (16:04 +0000)
committerstephan <stephan@noemail.net>
Thu, 7 Mar 2024 16:04:43 +0000 (16:04 +0000)
FossilOrigin-Name: 0e272123ace55ed63fe86632671cca48e8965a28fc3625324984028729fc203f

ext/wasm/GNUmakefile
ext/wasm/api/sqlite3-worker1-promiser.c-pp.js
ext/wasm/demo-worker1-promiser.js
manifest
manifest.uuid

index 098a4330b06e3b9e771e6f7c2e7b9f66350ee669..ff11ab6552ea272d5012abec7c7a300c96c3215d 100644 (file)
@@ -307,8 +307,9 @@ DISTCLEAN_FILES += $(bin.stripccomments)
 
 
 ########################################################################
-# C-PP.FILTER: a $(call)able to transform $(1) to $(2) via ./c-pp -f
-# $(1) ...
+# C-PP.FILTER: a $(call)able to transform $(1) to $(2) via:
+#
+#   ./c-pp -f $(1) -o $(2) $(3)
 #
 # Historical notes:
 #
@@ -825,13 +826,13 @@ pre-post-jses.deps.common := $(extern-pre-js.js) $(sqlite3-license-version.js)
 # $4 = resulting sqlite-api JS/MJS file
 # $5 = resulting JS/MJS file
 # $6 = -D... flags for $(bin.c-pp)
-# $7 = emcc -sXYZ flags (CURRENTLY UNUSED - was factored out)
+# $7 = optional extra flags for emcc
 #
 # Maintenance reminder: be careful not to introduce spaces around args
 # ($1, $2), otherwise string concatenation will malfunction.
 #
-# emcc.environment.$(2) must be set to a value for emcc's
-# -sENVIRONMENT flag.
+# Before calling this, emcc.environment.$(2) must be set to a value
+# for emcc's -sENVIRONMENT flag.
 #
 # $(cflags.$(1)) and $(cflags.$(1).$(2)) may be defined to append
 # CFLAGS to a given build mode.
@@ -938,6 +939,7 @@ sqlite3-worker1.js.in := $(dir.api)/sqlite3-worker1.c-pp.js
 sqlite3-worker1-promiser.js.in := $(dir.api)/sqlite3-worker1-promiser.c-pp.js
 sqlite3-worker1.js := $(dir.dout)/sqlite3-worker1.js
 sqlite3-worker1-promiser.js := $(dir.dout)/sqlite3-worker1-promiser.js
+sqlite3-worker1-promiser.mjs := $(dir.dout)/sqlite3-worker1-promiser.mjs
 sqlite3-worker1-bundler-friendly.js := $(dir.dout)/sqlite3-worker1-bundler-friendly.mjs
 sqlite3-worker1-promiser-bundler-friendly.js := $(dir.dout)/sqlite3-worker1-promiser-bundler-friendly.js
 $(eval $(call C-PP.FILTER,$(sqlite3-worker1.js.in),$(sqlite3-worker1.js)))
@@ -947,10 +949,12 @@ $(eval $(call C-PP.FILTER,$(sqlite3-worker1-promiser.js.in),$(sqlite3-worker1-pr
 $(eval $(call C-PP.FILTER,$(sqlite3-worker1-promiser.js.in),\
     $(sqlite3-worker1-promiser-bundler-friendly.js),\
     $(c-pp.D.sqlite3-bundler-friendly)))
+$(eval $(call C-PP.FILTER,$(sqlite3-worker1-promiser.js.in),$(sqlite3-worker1-promiser.mjs),\
+    -Dtarget=es6-module -Dtarget=es6-bundler-friendly))
 $(sqlite3-bundler-friendly.mjs): $(sqlite3-worker1-bundler-friendly.js) \
     $(sqlite3-worker1-promiser-bundler-friendly.js)
-$(sqlite3.js) $(sqlite3.mjs): $(sqlite3-worker1.js) $(sqlite3-worker1-promiser.js)
-
+$(sqlite3.js) $(sqlite3.mjs): $(sqlite3-worker1.js) \
+    $(sqlite3-worker1-promiser.js) $(sqlite3-worker1-promiser.mjs)
 ########################################################################
 # batch-runner.js is part of one of the test apps which reads in SQL
 # dumps generated by $(speedtest1) and executes them.
index 68846209e52a800e6a13cc627935ca092a76d169..5e399cd34439e8432fbb79aa4409ac9b3f0e1a29 100644 (file)
    - `onready` (optional, but...): this callback is called with no
    arguments when the worker fires its initial
    'sqlite3-api'/'worker1-ready' message, which it does when
-   sqlite3.initWorker1API() completes its initialization. This is
-   the simplest way to tell the worker to kick off work at the
-   earliest opportunity.
+   sqlite3.initWorker1API() completes its initialization. This is the
+   simplest way to tell the worker to kick off work at the earliest
+   opportunity, and the only way to know when the worker module has
+   completed loading. The irony of using a callback for this, instead
+   of returning a promise from sqlite3Worker1Promiser() is not lost on
+   the developers, but initial attempts to return a promise resulted
+   in a much clumsier interface.
 
    - `onunhandled` (optional): a callback which gets passed the
    message event object for any worker.onmessage() events which
@@ -277,7 +281,45 @@ globalThis.sqlite3Worker1Promiser.defaultConfig = {
 //#endif
   ,
   onerror: (...args)=>console.error('worker1 promiser error',...args)
+}/*defaultConfig*/;
+
+/**
+   sqlite3Worker1Promiser.v2() works identically to
+   sqlite3Worker1Promiser() except that it returns a promise instead
+   of relying an an onready callback in the config object.
+*/
+sqlite3Worker1Promiser.v2 = function(config){
+  const x = Object.create(null);
+  let oldFunc;
+  if( 'function' == typeof config ){
+    oldFunc = config;
+    config = {};
+  }else if('function'===typeof config?.onready){
+    oldFunc = config.onready;
+    delete config.onready;
+  }
+  config = Object.assign((config || Object.create(null)),{
+    onready: function(func){
+      try {
+        if( oldFunc ){
+          oldFunc(func);
+        }
+        x.resolve(func);
+      }
+      catch(e){x.reject(e)}
+    }
+  });
+  const p = new Promise(function(resolve,reject){
+    x.resolve = resolve;
+    x.reject = reject;
+  });
+  sqlite3Worker1Promiser(config);
+  return p;
 };
+
+//#if target=es6-module
+export default sqlite3Worker1Promiser.v2;
+//#endif /* target=es6-module */
 //#else
 /* Built with the omit-oo1 flag. */
 //#endif ifnot omit-oo1
index 4327f7487d7f921d32ca1a8e1e94ccbce188503f..19a7af114320bb8ec47c3f82626643a50f53cdac 100644 (file)
@@ -14,8 +14,8 @@
   proxy for for the sqlite3 Worker #1 API.
 */
 'use strict';
-(function(){
-  const T = self.SqliteTestUtil;
+(async function(){
+  const T = globalThis.SqliteTestUtil;
   const eOutput = document.querySelector('#test-output');
   const warn = console.warn.bind(console);
   const error = console.error.bind(console);
     onunhandled: function(ev){
       error("Unhandled worker message:",ev.data);
     },
-    onready: function(){
-      T.affirm(arguments[0] === workerPromise
-               /* as of version 3.46. Prior to that this callback had no arguments */);
-      self.sqlite3TestModule.setStatus(null)/*hide the HTML-side is-loading spinner*/;
-      runTests();
-    },
     onerror: function(ev){
       error("worker1 error:",ev);
+    },
+    onready: function(f){
+      warn("This is the v2 interface - don't pass an onready() function.");
     }
   };
-  const workerPromise = self.sqlite3Worker1Promiser(promiserConfig);
-  delete self.sqlite3Worker1Promiser;
+  const workerPromise = await globalThis.sqlite3Worker1Promiser.v2(promiserConfig)
+        .then((func)=>{
+          log("Init complete. Starting tests momentarily.");
+          globalThis.sqlite3TestModule.setStatus(null)/*hide the HTML-side is-loading spinner*/;
+          return func;
+        });
+  delete globalThis.sqlite3Worker1Promiser;
 
   const wtest = async function(msgType, msgArgs, callback){
     if(2===arguments.length && 'function'===typeof msgArgs){
     }).finally(()=>logHtml('',"That's all, folks!"));
   }/*runTests2()*/;
 
-  log("Init complete, but async init bits may still be running.");
+  runTests();
 })();
index da940666474e3f6b1bf4cf2412a8550286291bfe..9d045f3c98e793365e5113eb22467e69de06de3a 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Correction\sto\sthe\sprevious\scheck-in.
-D 2024-03-06T12:28:55.128
+C Initial\swork\sat\sgetting\ssqlite3Worker1Promiser.v2()\sto\sreturn\sa\sPromise\sinstead\sof\susing\san\sonready()\scallback,\sand\salso\screating\san\sESM\sbuild\sfor\spromiser1\sper\suser\srequest.\sIt\sseems\sto\swork\sbut\srequires\smore\stesting.
+D 2024-03-07T16:04:43.823
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -587,7 +587,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3
 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c
 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb
 F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c
-F ext/wasm/GNUmakefile 92e929315c3f1e0ea389fc9666b87a67a61fa1ecbe37e44c5ad226bda3bc6abe
+F ext/wasm/GNUmakefile e04f36fec0ab949424622a906020902651bd8d17f9696c56ed572eebc63e2355
 F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576
 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193
 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff
@@ -616,7 +616,7 @@ F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 5a430874906ff3f4a6ca69aadf0c2aae
 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js fe427645e1499618f5fa7bc670af850577d8bcc132df982078690c9bf8400baa
 F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309
 F ext/wasm/api/sqlite3-wasm.c d33a16495ca871781e78812d3a18fed78b797468fffee657b8d7199b277ff359
-F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js e8135b44a568badfe197e2379f6b42899f2240b5c3a77fa044331110f7ce8e50
+F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js c11220b21f748c955ca798ad43ba7fea75ca0bf8dba78f46508f09517de26c05
 F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5
 F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7
 F ext/wasm/batch-runner-sahpool.js 54a3ac228e6c4703fe72fb65c897e19156263a51fe9b7e21d2834a45e876aabd
@@ -633,7 +633,7 @@ F ext/wasm/demo-123.js c7b3cca50c55841c381a9ca4f9396e5bbdc6114273d0b10a43e378e32
 F ext/wasm/demo-jsstorage.html 409c4be4af5f207fb2877160724b91b33ea36a3cd8c204e8da1acb828ffe588e
 F ext/wasm/demo-jsstorage.js 44e3ae7ec2483b6c511384c3c290beb6f305c721186bcf5398ca4e00004a06b8
 F ext/wasm/demo-worker1-promiser.html 1de7c248c7c2cfd4a5783d2aa154bce62d74c6de98ab22f5786620b3354ed15f
-F ext/wasm/demo-worker1-promiser.js 786ae8a3214c2a29f6fb2c80eb4f90cc401fcc5b524d95c35fdc66a454e32bad
+F ext/wasm/demo-worker1-promiser.js e4cd1089269d106dd3bd20684eaddcd176c73baa31867ba0e445c8e7e29160b5
 F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2eb1ab2c68ef5d
 F ext/wasm/demo-worker1.js 836bece8615b17b1b572584f7b15912236a5947fe8c68b98d2737d7e287447ef
 F ext/wasm/dist.make 3a851858aad72e246a5d9c5aaf6b6a144305f1bf898ac1846760ea7bab95c9a3
@@ -2176,8 +2176,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 027e5336acc26f57f21df4980928731026c30cf88688fa0b66f13ffa0b5da3a0
-R ee785ecad1867a820bb9e665fd92d3e8
-U drh
-Z 74daf43f110405d8b8bf503998b8174f
+P 483fa2969e1e10cd8e8d2f9e3027871c65b1360b6c23897efe3ce63a3a55ae13
+R fb2d3021442c55c82ff56e48b32fdd31
+T *branch * wasm-promiser1-v2
+T *sym-wasm-promiser1-v2 *
+T -sym-trunk * Cancelled\sby\sbranch.
+U stephan
+Z d10f630418c41733e8d0108d272da900
 # Remove this line to create a well-formed Fossil manifest.
index dba854ccd33841b949b504f3bb8dc5e8f6c0684a..145a2be6b8f31ba386e540e6abd4af537366effa 100644 (file)
@@ -1 +1 @@
-483fa2969e1e10cd8e8d2f9e3027871c65b1360b6c23897efe3ce63a3a55ae13
\ No newline at end of file
+0e272123ace55ed63fe86632671cca48e8965a28fc3625324984028729fc203f
\ No newline at end of file