diff options
author | stephan <stephan@noemail.net> | 2022-09-30 23:02:11 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-09-30 23:02:11 +0000 |
commit | ae589b69db0ac266f09b9e60be2eaee5e3c8e601 (patch) | |
tree | 4840d5a010d42495681452494d76941079b790b7 /ext/wasm/sqlite3-worker1-promiser.js | |
parent | e67a0f40e419f4945d8157cb047ae302bf1f2852 (diff) | |
download | sqlite-ae589b69db0ac266f09b9e60be2eaee5e3c8e601.tar.gz sqlite-ae589b69db0ac266f09b9e60be2eaee5e3c8e601.zip |
Tweaks to the Worker1 and Promiser APIs prompted by documenting them.
FossilOrigin-Name: c68b9aa160e2c1197ae7eb06a634017ac2b281393074afa4582762d5458c6889
Diffstat (limited to 'ext/wasm/sqlite3-worker1-promiser.js')
-rw-r--r-- | ext/wasm/sqlite3-worker1-promiser.js | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/ext/wasm/sqlite3-worker1-promiser.js b/ext/wasm/sqlite3-worker1-promiser.js index c683e2fb7..0b611e0c9 100644 --- a/ext/wasm/sqlite3-worker1-promiser.js +++ b/ext/wasm/sqlite3-worker1-promiser.js @@ -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; |