diff options
author | stephan <stephan@noemail.net> | 2022-11-21 05:18:24 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-11-21 05:18:24 +0000 |
commit | b38ac0986e86d56115396c36355d4e751cc4f7f5 (patch) | |
tree | 33d263ac06b881ac99bad30730d42a62543b7f94 /ext/wasm/tests/opfs/concurrency/worker.js | |
parent | 36d5554c9abaa3080e85e3b7b517605c6106587d (diff) | |
download | sqlite-b38ac0986e86d56115396c36355d4e751cc4f7f5.tar.gz sqlite-b38ac0986e86d56115396c36355d4e751cc4f7f5.zip |
More tweaking of OPFS concurrency measures and the related test app.
FossilOrigin-Name: a8d4da1501d411085ec2fd48c4a056c8b1d97ef3c3203c5b403a854ac2864870
Diffstat (limited to 'ext/wasm/tests/opfs/concurrency/worker.js')
-rw-r--r-- | ext/wasm/tests/opfs/concurrency/worker.js | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/ext/wasm/tests/opfs/concurrency/worker.js b/ext/wasm/tests/opfs/concurrency/worker.js index 9aaa2f4c7..85a5cf19b 100644 --- a/ext/wasm/tests/opfs/concurrency/worker.js +++ b/ext/wasm/tests/opfs/concurrency/worker.js @@ -8,7 +8,6 @@ self.sqlite3InitModule().then(async function(sqlite3){ }; const stdout = (...args)=>wPost('stdout',...args); const stderr = (...args)=>wPost('stderr',...args); - const postErr = (...args)=>wPost('error',...args); if(!sqlite3.opfs){ stderr("OPFS support not detected. Aborting."); return; @@ -19,15 +18,33 @@ self.sqlite3InitModule().then(async function(sqlite3){ }; const dbName = 'concurrency-tester.db'; - if((new URL(self.location.href).searchParams).has('unlink-db')){ + const urlArgs = new URL(self.location.href).searchParams; + if(urlArgs.has('unlink-db')){ await sqlite3.opfs.unlink(dbName); stdout("Unlinked",dbName); } wPost('loaded'); - + let db; + const interval = Object.assign(Object.create(null),{ + delay: urlArgs.has('interval') ? (+urlArgs.get('interval') || 750) : 750, + handle: undefined, + count: 0 + }); + const finish = ()=>{ + if(db){ + if(!db.pointer) return; + db.close(); + } + if(interval.error){ + wPost('failed',"Ending work after interval #"+interval.count, + "due to error:",interval.error); + }else{ + wPost('finished',"Ending work after",interval.count,"intervals."); + } + }; const run = async function(){ - const db = new sqlite3.opfs.OpfsDb(dbName,'c'); - //sqlite3.capi.sqlite3_busy_timeout(db.pointer, 2000); + db = new sqlite3.opfs.OpfsDb(dbName,'c'); + sqlite3.capi.sqlite3_busy_timeout(db.pointer, 5000); db.transaction((db)=>{ db.exec([ "create table if not exists t1(w TEXT UNIQUE ON CONFLICT REPLACE,v);", @@ -36,11 +53,6 @@ self.sqlite3InitModule().then(async function(sqlite3){ }); const maxIterations = 10; - const interval = Object.assign(Object.create(null),{ - delay: 500, - handle: undefined, - count: 0 - }); stdout("Starting interval-based db updates with delay of",interval.delay,"ms."); const doWork = async ()=>{ const tm = new Date().getTime(); @@ -57,15 +69,6 @@ self.sqlite3InitModule().then(async function(sqlite3){ interval.error = e; } }; - const finish = ()=>{ - db.close(); - if(interval.error){ - wPost('failed',"Ending work after interval #"+interval.count, - "due to error:",interval.error); - }else{ - wPost('finished',"Ending work after",interval.count,"intervals."); - } - }; if(1){/*use setInterval()*/ interval.handle = setInterval(async ()=>{ await doWork(); @@ -89,7 +92,10 @@ self.sqlite3InitModule().then(async function(sqlite3){ self.onmessage = function({data}){ switch(data.type){ - case 'run': run().catch((e)=>postErr(e.message)); + case 'run': run().catch((e)=>{ + if(!interval.error) interval.error = e; + finish(); + }); break; default: stderr("Unhandled message type '"+data.type+"'."); |