1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-27 20:41:58 +03:00

Tweaks to the Worker1 and Promiser APIs prompted by documenting them.

FossilOrigin-Name: c68b9aa160e2c1197ae7eb06a634017ac2b281393074afa4582762d5458c6889
This commit is contained in:
stephan
2022-09-30 23:02:11 +00:00
parent e67a0f40e4
commit ae589b69db
5 changed files with 27 additions and 33 deletions

View File

@ -159,7 +159,7 @@
bigIntEnabled: bool. True if BigInt support is enabled.
wasmfsOpfsDir: path prefix, if any, _intended_ for use with
OPFS persistent storage.
WASMFS OPFS persistent storage.
wasmfsOpfsEnabled: true if persistent storage is enabled in the
current environment. Only files stored under wasmfsOpfsDir
@ -188,15 +188,6 @@
See the sqlite3.oo1.DB constructor for peculiarities and
transformations,
persistent [=false]: if true and filename is not one of ("",
":memory:"), prepend sqlite3.capi.sqlite3_wasmfs_opfs_dir()
to the given filename so that it is stored in persistent storage
_if_ the environment supports it. If persistent storage is not
supported, the filename is used as-is.
// TODO?: ^^^^ maybe rework that, now that we have the non-WASMFS
// OFPS.
}
}
```
@ -218,8 +209,7 @@
Only the `open` operation includes it in the `result` property.
persistent: true if the given filename resides in the
known-persistent storage, else false. This determination is
independent of the `persistent` input argument.
known-persistent storage, else false.
}
}
@ -239,7 +229,7 @@
unlink: if truthy, the associated db will be unlinked (removed)
from the virtual filesystems. Failure to unlink is silently
ignored.
ignored. Does not currently work for all storage backends.
}
}
@ -324,7 +314,7 @@
layer won't emit a result value of `undefined`.)
The callback proxy must not recurse into this interface. An exec()
call will type up the Worker thread, causing any recursion attempt
call will tie up the Worker thread, causing any recursion attempt
to wait until the first exec() is completed.
The response is the input options object (or a synthesized one if

View File

@ -32,10 +32,10 @@
It requires a configuration object with the following properties:
- `worker` (required): a Worker instance which loads
`sqlite3-worker1.js` or a functional equivalent. Note that this
function replaces the worker.onmessage property. This property
may alternately be a function, in which case this function
re-assigns this property with the result of calling that
`sqlite3-worker1.js` or a functional equivalent. Note that the
promiser factory replaces the worker.onmessage property. This
config option may alternately be a function, in which case this
function re-assigns this property with the result of calling that
function, enabling delayed instantiation of a Worker.
- `onready` (optional, but...): this callback is called with no
@ -147,6 +147,14 @@
*/
self.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){
// Inspired by: https://stackoverflow.com/a/52439530
if(1===arguments.length && 'function'===typeof arguments[0]){
const f = config;
config = Object.assign(Object.create(null), callee.defaultConfig);
config.onready = f;
}
/* 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 noop = function(){};
const err = config.onerror || noop;
@ -156,6 +164,7 @@ self.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){
return msg.type+'#'+(idTypeMap[msg.type] = (idTypeMap[msg.type]||0) + 1);
};
const toss = (...args)=>{throw new Error(args.join(' '))};
if(!config.worker) config.worker = callee.defaultConfig.worker;
if('function'===typeof config.worker) config.worker = config.worker();
config.worker.onmessage = function(ev){
ev = ev.data;

View File

@ -86,16 +86,11 @@
await wtest('open', {
filename: dbFilename,
persistent: sqConfig.wasmfsOpfsEnabled,
simulateError: 0 /* if true, fail the 'open' */,
}, function(ev){
const r = ev.result;
log("then open result",r);
T.assert(r.persistent === sqConfig.wasmfsOpfsEnabled)
.assert(r.persistent
? (dbFilename!==r.filename)
: (dbFilename==r.filename))
.assert(ev.dbId === r.dbId)
T.assert(ev.dbId === r.dbId)
.assert(ev.messageId)
.assert(promiserConfig.dbId === ev.dbId);
}).then(runTests2);