diff options
author | stephan <stephan@noemail.net> | 2025-01-31 17:47:47 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2025-01-31 17:47:47 +0000 |
commit | cee760907489075386e27c37fe6c86c835604857 (patch) | |
tree | f86db84da7627a8d43163a86e75a96bb3af5680d /ext/wasm | |
parent | a75321d73572305588d51d90a824f260f4b44681 (diff) | |
download | sqlite-cee760907489075386e27c37fe6c86c835604857.tar.gz sqlite-cee760907489075386e27c37fe6c86c835604857.zip |
Minor cleanups in the opfs-sahpool pause/unpause API demo.
FossilOrigin-Name: e205cdc468e02eefdeb8d391d921aa2d4d28a8b7b87036d6d937a9928261a413
Diffstat (limited to 'ext/wasm')
-rw-r--r-- | ext/wasm/api/sqlite3-worker1-promiser.c-pp.js | 4 | ||||
-rw-r--r-- | ext/wasm/tests/opfs/sahpool/sahpool-pausing.js | 27 |
2 files changed, 21 insertions, 10 deletions
diff --git a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js index 55e497ead..c043fd148 100644 --- a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js +++ b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js @@ -335,8 +335,8 @@ sqlite3Worker1Promiser.v2 = function(config){ /** When built as a module, we export sqlite3Worker1Promiser.v2() instead of sqlite3Worker1Promise() because (A) its interface is more - conventional for ESM usage and (B) the ESM option export option for - this API did not exist until v2 was created, so there's no backwards + conventional for ESM usage and (B) the ESM export option for this + API did not exist until v2 was created, so there's no backwards incompatibility. */ export default sqlite3Worker1Promiser.v2; diff --git a/ext/wasm/tests/opfs/sahpool/sahpool-pausing.js b/ext/wasm/tests/opfs/sahpool/sahpool-pausing.js index 6a4cfbc9f..1aa98d3cb 100644 --- a/ext/wasm/tests/opfs/sahpool/sahpool-pausing.js +++ b/ext/wasm/tests/opfs/sahpool/sahpool-pausing.js @@ -12,9 +12,12 @@ These tests are specific to the opfs-sahpool VFS and are limited to demonstrating its pause/unpause capabilities. + + Most of this file is infrastructure for displaying results to the + user. Search for runTests() to find where the work actually starts. */ 'use strict'; -(function(self){ +(function(){ let logClass; const mapToString = (v)=>{ @@ -35,7 +38,6 @@ return JSON.stringify(v,undefined,2); }; const normalizeArgs = (args)=>args.map(mapToString); - console.log("Running in the UI thread."); const logTarget = document.querySelector('#test-output'); logClass = function(cssClass,...args){ const ln = document.createElement('div'); @@ -78,8 +80,6 @@ throw new Error(args.join(' ')); }; - const nextHandlerQueue = []; - const endOfWork = (passed=true)=>{ const eH = document.querySelector('#color-target'); const eT = document.querySelector('title'); @@ -95,6 +95,8 @@ } }; + const nextHandlerQueue = []; + const nextHandler = function(workerId,...msg){ log(workerId,...msg); (nextHandlerQueue.shift())(); @@ -105,7 +107,16 @@ W.postMessage({type:msgType}); }; - const runTriangleOfDeath = function(W1, W2){ + /** + Run a series of operations on an sahpool db spanning two workers. + This would arguably be more legible with Promises, but creating a + Promise-based communication channel for this purpose is left as + an exercise for the reader. An example of such a proxy can be + found in the SQLite source tree: + + https://sqlite.org/src/file/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js + */ + const runPyramidOfDoom = function(W1, W2){ postThen(W1, 'vfs-acquire', function(){ postThen(W1, 'db-init', function(){ postThen(W1, 'db-query', function(){ @@ -122,7 +133,7 @@ }; const runTests = function(){ - log("Running sahpool pausing tests..."); + log("Running opfs-sahpool pausing tests..."); const wjs = 'sahpool-worker.js?sqlite3.dir=../../../jswasm'; const W1 = new Worker(wjs+'&workerId=w1'), W2 = new Worker(wjs+'&workerId=w2'); @@ -160,7 +171,7 @@ case 'initialized': log(data.workerId, ': Worker initialized',...data.payload); if( 2===++initCount ){ - runTriangleOfDeath(W1, W2); + runPyramidOfDoom(W1, W2); } break; } @@ -169,4 +180,4 @@ }; runTests(); -})(globalThis); +})(); |