mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Remove a couple of weird quirks of the Worker1 and Promiser APIs. The Worker1 (now undocumented) unlink capability needs to be reevaluated to work equivalently for all storage backends.
FossilOrigin-Name: 9f2b331a32cbaadfd20d04c9908171355322c1aa1d9d6df3628f3b2fb4391ec1
This commit is contained in:
@@ -225,13 +225,7 @@
|
|||||||
type: "close",
|
type: "close",
|
||||||
messageId: ...as above...
|
messageId: ...as above...
|
||||||
dbId: ...as above...
|
dbId: ...as above...
|
||||||
args: OPTIONAL: {
|
args: none
|
||||||
|
|
||||||
unlink: if truthy, the associated db will be unlinked (removed)
|
|
||||||
from the virtual filesystems. Failure to unlink is silently
|
|
||||||
ignored. Does not currently work for all storage backends.
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -460,6 +454,8 @@ sqlite3.initWorker1API = function(){
|
|||||||
filename: db && db.filename
|
filename: db && db.filename
|
||||||
};
|
};
|
||||||
if(db){
|
if(db){
|
||||||
|
// Keep the "unlink" flag undocumented until we figure out how
|
||||||
|
// to apply it consistently, independent of the db storage.
|
||||||
wState.close(db, ((ev.args && 'object'===typeof ev.args)
|
wState.close(db, ((ev.args && 'object'===typeof ev.args)
|
||||||
? !!ev.args.unlink : false));
|
? !!ev.args.unlink : false));
|
||||||
}
|
}
|
||||||
|
@@ -45,11 +45,6 @@
|
|||||||
the simplest way to tell the worker to kick off work at the
|
the simplest way to tell the worker to kick off work at the
|
||||||
earliest opportunity.
|
earliest opportunity.
|
||||||
|
|
||||||
- `onerror` (optional): a callback to pass error-type events from
|
|
||||||
the worker. The object passed to it will be the error message
|
|
||||||
payload from the worker. This is _not_ the same as the
|
|
||||||
worker.onerror property!
|
|
||||||
|
|
||||||
- `onunhandled` (optional): a callback which gets passed the
|
- `onunhandled` (optional): a callback which gets passed the
|
||||||
message event object for any worker.onmessage() events which
|
message event object for any worker.onmessage() events which
|
||||||
are not handled by this proxy. Ideally that "should" never
|
are not handled by this proxy. Ideally that "should" never
|
||||||
@@ -62,21 +57,6 @@
|
|||||||
so that dispatching can work. If not defined, a default generator
|
so that dispatching can work. If not defined, a default generator
|
||||||
is used (which should be sufficient for most or all cases).
|
is used (which should be sufficient for most or all cases).
|
||||||
|
|
||||||
- `dbId` (optional): is the database ID to be used by the
|
|
||||||
worker. This must initially be unset or a falsy value. The
|
|
||||||
first `open` message sent to the worker will cause this config
|
|
||||||
entry to be assigned to the ID of the opened database. That ID
|
|
||||||
"should" be set as the `dbId` property of the messages sent in
|
|
||||||
future requests, so that the worker uses that database.
|
|
||||||
However, if the worker is not given an explicit dbId, it will
|
|
||||||
use the first-opened database by default. If client code needs
|
|
||||||
to work with multiple database IDs, the client-level code will
|
|
||||||
need to juggle those themselves. A `close` message will clear
|
|
||||||
this property if it matches the ID of the closed db. Potential
|
|
||||||
TODO: add a config callback specifically for reporting `open`
|
|
||||||
and `close` message results, so that clients may track those
|
|
||||||
values.
|
|
||||||
|
|
||||||
- `debug` (optional): a console.debug()-style function for logging
|
- `debug` (optional): a console.debug()-style function for logging
|
||||||
information about messages.
|
information about messages.
|
||||||
|
|
||||||
@@ -110,14 +90,9 @@
|
|||||||
const sq3Promiser = sqlite3Worker1Promiser(config);
|
const sq3Promiser = sqlite3Worker1Promiser(config);
|
||||||
sq3Promiser('open', {filename:"/foo.db"}).then(function(msg){
|
sq3Promiser('open', {filename:"/foo.db"}).then(function(msg){
|
||||||
console.log("open response",msg); // => {type:'open', result: {filename:'/foo.db'}, ...}
|
console.log("open response",msg); // => {type:'open', result: {filename:'/foo.db'}, ...}
|
||||||
// Recall that config.dbId will be set for the first 'open'
|
|
||||||
// call and cleared for a matching 'close' call.
|
|
||||||
});
|
});
|
||||||
sq3Promiser({type:'close'}).then((msg)=>{
|
sq3Promiser({type:'close'}).then((msg)=>{
|
||||||
console.log("close response",msg); // => {type:'close', result: {filename:'/foo.db'}, ...}
|
console.log("close response",msg); // => {type:'close', result: {filename:'/foo.db'}, ...}
|
||||||
// Recall that config.dbId will be used by default for the message's dbId if
|
|
||||||
// none is explicitly provided, and a 'close' op will clear config.dbId if it
|
|
||||||
// closes that exact db.
|
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -151,13 +126,14 @@ self.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){
|
|||||||
const f = config;
|
const f = config;
|
||||||
config = Object.assign(Object.create(null), callee.defaultConfig);
|
config = Object.assign(Object.create(null), callee.defaultConfig);
|
||||||
config.onready = f;
|
config.onready = f;
|
||||||
|
}else{
|
||||||
|
config = Object.assign(Object.create(null), callee.defaultConfig, config);
|
||||||
}
|
}
|
||||||
/* Maintenance reminder: when passed a config object, the reference
|
|
||||||
must be used as-is, instead of normalizing it to another object,
|
|
||||||
so that we can communicate the dbId through it. */
|
|
||||||
const handlerMap = Object.create(null);
|
const handlerMap = Object.create(null);
|
||||||
const noop = function(){};
|
const noop = function(){};
|
||||||
const err = config.onerror || noop;
|
const err = config.onerror
|
||||||
|
|| noop /* config.onerror is intentionally undocumented
|
||||||
|
pending finding a less ambiguous name */;
|
||||||
const debug = config.debug || noop;
|
const debug = config.debug || noop;
|
||||||
const idTypeMap = config.generateMessageId ? undefined : Object.create(null);
|
const idTypeMap = config.generateMessageId ? undefined : Object.create(null);
|
||||||
const genMsgId = config.generateMessageId || function(msg){
|
const genMsgId = config.generateMessageId || function(msg){
|
||||||
@@ -166,6 +142,7 @@ self.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){
|
|||||||
const toss = (...args)=>{throw new Error(args.join(' '))};
|
const toss = (...args)=>{throw new Error(args.join(' '))};
|
||||||
if(!config.worker) config.worker = callee.defaultConfig.worker;
|
if(!config.worker) config.worker = callee.defaultConfig.worker;
|
||||||
if('function'===typeof config.worker) config.worker = config.worker();
|
if('function'===typeof config.worker) config.worker = config.worker();
|
||||||
|
let dbId;
|
||||||
config.worker.onmessage = function(ev){
|
config.worker.onmessage = function(ev){
|
||||||
ev = ev.data;
|
ev = ev.data;
|
||||||
debug('worker1.onmessage',ev);
|
debug('worker1.onmessage',ev);
|
||||||
@@ -191,10 +168,10 @@ self.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){
|
|||||||
msgHandler.reject(ev);
|
msgHandler.reject(ev);
|
||||||
return;
|
return;
|
||||||
case 'open':
|
case 'open':
|
||||||
if(!config.dbId) config.dbId = ev.dbId;
|
if(!dbId) dbId = ev.dbId;
|
||||||
break;
|
break;
|
||||||
case 'close':
|
case 'close':
|
||||||
if(config.dbId === ev.dbId) config.dbId = undefined;
|
if(ev.dbId===dbId) dbId = undefined;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -214,7 +191,7 @@ self.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){
|
|||||||
}else{
|
}else{
|
||||||
toss("Invalid arugments for sqlite3Worker1Promiser()-created factory.");
|
toss("Invalid arugments for sqlite3Worker1Promiser()-created factory.");
|
||||||
}
|
}
|
||||||
if(!msg.dbId) msg.dbId = config.dbId;
|
if(!msg.dbId) msg.dbId = dbId;
|
||||||
msg.messageId = genMsgId(msg);
|
msg.messageId = genMsgId(msg);
|
||||||
msg.departureTime = performance.now();
|
msg.departureTime = performance.now();
|
||||||
const proxy = Object.create(null);
|
const proxy = Object.create(null);
|
||||||
@@ -249,7 +226,7 @@ self.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){
|
|||||||
proxy.resolve = resolve;
|
proxy.resolve = resolve;
|
||||||
proxy.reject = reject;
|
proxy.reject = reject;
|
||||||
handlerMap[msg.messageId] = proxy;
|
handlerMap[msg.messageId] = proxy;
|
||||||
debug("Posting",msg.type,"message to Worker dbId="+(config.dbId||'default')+':',msg);
|
debug("Posting",msg.type,"message to Worker dbId="+(dbId||'default')+':',msg);
|
||||||
config.worker.postMessage(msg);
|
config.worker.postMessage(msg);
|
||||||
});
|
});
|
||||||
if(rowCallbackId) p = p.finally(()=>delete handlerMap[rowCallbackId]);
|
if(rowCallbackId) p = p.finally(()=>delete handlerMap[rowCallbackId]);
|
||||||
@@ -261,6 +238,5 @@ self.sqlite3Worker1Promiser.defaultConfig = {
|
|||||||
//const p = self.location.pathname.replace(/[^/]*$/, "sqlite3-worker1.js");
|
//const p = self.location.pathname.replace(/[^/]*$/, "sqlite3-worker1.js");
|
||||||
return new Worker("sqlite3-worker1.js");
|
return new Worker("sqlite3-worker1.js");
|
||||||
},
|
},
|
||||||
onerror: (...args)=>console.error('worker1 error',...args),
|
onerror: (...args)=>console.error('worker1 promiser error',...args)
|
||||||
dbId: undefined
|
|
||||||
};
|
};
|
||||||
|
@@ -91,8 +91,8 @@
|
|||||||
const r = ev.result;
|
const r = ev.result;
|
||||||
log("then open result",r);
|
log("then open result",r);
|
||||||
T.assert(ev.dbId === r.dbId)
|
T.assert(ev.dbId === r.dbId)
|
||||||
.assert(ev.messageId)
|
.assert(ev.messageId);
|
||||||
.assert(promiserConfig.dbId === ev.dbId);
|
promiserConfig.dbId = ev.dbId;
|
||||||
}).then(runTests2);
|
}).then(runTests2);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -248,8 +248,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
/***** close() tests must come last. *****/
|
/***** close() tests must come last. *****/
|
||||||
await wtest('close',{unlink:true},function(ev){
|
await wtest('close',{},function(ev){
|
||||||
T.assert(!promiserConfig.dbId);
|
|
||||||
T.assert('string' === typeof ev.result.filename);
|
T.assert('string' === typeof ev.result.filename);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -258,6 +257,5 @@
|
|||||||
}).finally(()=>logHtml('',"That's all, folks!"));
|
}).finally(()=>logHtml('',"That's all, folks!"));
|
||||||
}/*runTests2()*/;
|
}/*runTests2()*/;
|
||||||
|
|
||||||
|
|
||||||
log("Init complete, but async init bits may still be running.");
|
log("Init complete, but async init bits may still be running.");
|
||||||
})();
|
})();
|
||||||
|
16
manifest
16
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Tweaks\sto\sthe\sWorker1\sand\sPromiser\sAPIs\sprompted\sby\sdocumenting\sthem.
|
C Remove\sa\scouple\sof\sweird\squirks\sof\sthe\sWorker1\sand\sPromiser\sAPIs.\sThe\sWorker1\s(now\sundocumented)\sunlink\scapability\sneeds\sto\sbe\sreevaluated\sto\swork\sequivalently\sfor\sall\sstorage\sbackends.
|
||||||
D 2022-09-30T23:02:11.824
|
D 2022-09-30T23:49:43.818
|
||||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||||
@@ -489,7 +489,7 @@ F ext/wasm/api/sqlite3-api-glue.js ead29e6008ba148e7c67ad2bd928819dc72313ad2dcd3
|
|||||||
F ext/wasm/api/sqlite3-api-oo1.js 9caed0757a5e039ed92467e827fd3ca347fa08f19fe086fcbdd14a4ebe9c2f01
|
F ext/wasm/api/sqlite3-api-oo1.js 9caed0757a5e039ed92467e827fd3ca347fa08f19fe086fcbdd14a4ebe9c2f01
|
||||||
F ext/wasm/api/sqlite3-api-opfs.js 1b097808b7b081b0f0700cf97d49ef19760e401706168edff9cd45cf9169f541
|
F ext/wasm/api/sqlite3-api-opfs.js 1b097808b7b081b0f0700cf97d49ef19760e401706168edff9cd45cf9169f541
|
||||||
F ext/wasm/api/sqlite3-api-prologue.js cac3bc095171dca4aaf3611e0dd60a850c8e9fbeeeba8f21792ed1948d24dacc
|
F ext/wasm/api/sqlite3-api-prologue.js cac3bc095171dca4aaf3611e0dd60a850c8e9fbeeeba8f21792ed1948d24dacc
|
||||||
F ext/wasm/api/sqlite3-api-worker1.js 5fb9d178be5215107fc97eb67b9364d0ade3d4a90194b07a630afe6103c83408
|
F ext/wasm/api/sqlite3-api-worker1.js 7f4f46cb6b512a48572d7567233896e6a9c46570c44bdc3d13419730c7c221c8
|
||||||
F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9
|
F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9
|
||||||
F ext/wasm/api/sqlite3-wasm.c 336389b23c9b83763177499e49a0967949c392b2f7d84fbbb52ad6678e159f18
|
F ext/wasm/api/sqlite3-wasm.c 336389b23c9b83763177499e49a0967949c392b2f7d84fbbb52ad6678e159f18
|
||||||
F ext/wasm/batch-runner.html c363032aba7a525920f61f8be112a29459f73f07e46f0ba3b7730081a617826e
|
F ext/wasm/batch-runner.html c363032aba7a525920f61f8be112a29459f73f07e46f0ba3b7730081a617826e
|
||||||
@@ -523,12 +523,12 @@ F ext/wasm/split-speedtest1-script.sh a3e271938d4d14ee49105eb05567c6a69ba4c1f129
|
|||||||
F ext/wasm/sql/000-mandelbrot.sql 775337a4b80938ac8146aedf88808282f04d02d983d82675bd63d9c2d97a15f0
|
F ext/wasm/sql/000-mandelbrot.sql 775337a4b80938ac8146aedf88808282f04d02d983d82675bd63d9c2d97a15f0
|
||||||
F ext/wasm/sql/001-sudoku.sql 35b7cb7239ba5d5f193bc05ec379bcf66891bce6f2a5b3879f2f78d0917299b5
|
F ext/wasm/sql/001-sudoku.sql 35b7cb7239ba5d5f193bc05ec379bcf66891bce6f2a5b3879f2f78d0917299b5
|
||||||
F ext/wasm/sqlite3-opfs-async-proxy.js 7367733ce409c8106b6c49e8ef2b55440e9974a64f39e0c97f5e3a4587d1fc2a
|
F ext/wasm/sqlite3-opfs-async-proxy.js 7367733ce409c8106b6c49e8ef2b55440e9974a64f39e0c97f5e3a4587d1fc2a
|
||||||
F ext/wasm/sqlite3-worker1-promiser.js 4769b7a0a3d5fa1594ca555e8a3050c17f000fdebdabbc77c31a339ec914c405
|
F ext/wasm/sqlite3-worker1-promiser.js 8f5aca965f2b3e8096347d3db02f4502774c4390b1b62f11ae0f4869787feeac
|
||||||
F ext/wasm/sqlite3-worker1.js 5266ebc4d709fe23d2d076ae44e6085fbc32b82f26ef514b947312f36b1206a9
|
F ext/wasm/sqlite3-worker1.js 5266ebc4d709fe23d2d076ae44e6085fbc32b82f26ef514b947312f36b1206a9
|
||||||
F ext/wasm/test-opfs-vfs.html eb69dda21eb414b8f5e3f7c1cc0f774103cc9c0f87b2d28a33419e778abfbab5
|
F ext/wasm/test-opfs-vfs.html eb69dda21eb414b8f5e3f7c1cc0f774103cc9c0f87b2d28a33419e778abfbab5
|
||||||
F ext/wasm/test-opfs-vfs.js a59ff9210b17d46b0c6fbf6a0ba60143c033327865f2e556e14f06280cef62ac
|
F ext/wasm/test-opfs-vfs.js a59ff9210b17d46b0c6fbf6a0ba60143c033327865f2e556e14f06280cef62ac
|
||||||
F ext/wasm/testing-worker1-promiser.html 6eaec6e04a56cf24cf4fa8ef49d78ce8905dde1354235c9125dca6885f7ce893
|
F ext/wasm/testing-worker1-promiser.html 6eaec6e04a56cf24cf4fa8ef49d78ce8905dde1354235c9125dca6885f7ce893
|
||||||
F ext/wasm/testing-worker1-promiser.js 4de504b3c79564f0b3975c5e652b4bc16e37d2cc2e29b3a06233a17df5ad8eed
|
F ext/wasm/testing-worker1-promiser.js bd788e33c1807e0a6dda9c9a9d784bd3350ca49c9dd8ae2cc8719b506b6e013e
|
||||||
F ext/wasm/testing1.html 50575755e43232dbe4c2f97c9086b3118eb91ec2ee1fae931e6d7669fb17fcae
|
F ext/wasm/testing1.html 50575755e43232dbe4c2f97c9086b3118eb91ec2ee1fae931e6d7669fb17fcae
|
||||||
F ext/wasm/testing1.js 5584e9b68f797dbc0f6161360f2c6840169533813d92c74d355a3e78dd5bb539
|
F ext/wasm/testing1.js 5584e9b68f797dbc0f6161360f2c6840169533813d92c74d355a3e78dd5bb539
|
||||||
F ext/wasm/testing2.html a66951c38137ff1d687df79466351f3c734fa9c6d9cce71d3cf97c291b2167e3
|
F ext/wasm/testing2.html a66951c38137ff1d687df79466351f3c734fa9c6d9cce71d3cf97c291b2167e3
|
||||||
@@ -2029,8 +2029,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
|||||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||||
P 96818aa83f4ccc574f558231249ecbdd39763b4351cf4cf6d33f53774a3ee5e6
|
P c68b9aa160e2c1197ae7eb06a634017ac2b281393074afa4582762d5458c6889
|
||||||
R 572b0ac83bec64a69d8e85421a244ded
|
R 049b4866f034ceed644fe53d6e8f46f9
|
||||||
U stephan
|
U stephan
|
||||||
Z 43e7dcdb92d55bec08378952a610d517
|
Z f5dc0abfcbfb5f7170f7523cda76f56b
|
||||||
# Remove this line to create a well-formed Fossil manifest.
|
# Remove this line to create a well-formed Fossil manifest.
|
||||||
|
@@ -1 +1 @@
|
|||||||
c68b9aa160e2c1197ae7eb06a634017ac2b281393074afa4582762d5458c6889
|
9f2b331a32cbaadfd20d04c9908171355322c1aa1d9d6df3628f3b2fb4391ec1
|
Reference in New Issue
Block a user