the simplest way to tell the worker to kick off work at the
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
message event object for any worker.onmessage() events which
are not handled by this proxy. Ideally that "should" never
so that dispatching can work. If not defined, a default generator
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
information about messages.
const sq3Promiser = sqlite3Worker1Promiser(config);
sq3Promiser('open', {filename:"/foo.db"}).then(function(msg){
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)=>{
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.
});
```
const f = config;
config = Object.assign(Object.create(null), callee.defaultConfig);
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 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 idTypeMap = config.generateMessageId ? undefined : Object.create(null);
const genMsgId = config.generateMessageId || function(msg){
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();
+ let dbId;
config.worker.onmessage = function(ev){
ev = ev.data;
debug('worker1.onmessage',ev);
msgHandler.reject(ev);
return;
case 'open':
- if(!config.dbId) config.dbId = ev.dbId;
+ if(!dbId) dbId = ev.dbId;
break;
case 'close':
- if(config.dbId === ev.dbId) config.dbId = undefined;
+ if(ev.dbId===dbId) dbId = undefined;
break;
default:
break;
}else{
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.departureTime = performance.now();
const proxy = Object.create(null);
proxy.resolve = resolve;
proxy.reject = reject;
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);
});
if(rowCallbackId) p = p.finally(()=>delete handlerMap[rowCallbackId]);
//const p = self.location.pathname.replace(/[^/]*$/, "sqlite3-worker1.js");
return new Worker("sqlite3-worker1.js");
},
- onerror: (...args)=>console.error('worker1 error',...args),
- dbId: undefined
+ onerror: (...args)=>console.error('worker1 promiser error',...args)
};
-C Tweaks\sto\sthe\sWorker1\sand\sPromiser\sAPIs\sprompted\sby\sdocumenting\sthem.
-D 2022-09-30T23:02:11.824
+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:49:43.818
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
F ext/wasm/api/sqlite3-api-oo1.js 9caed0757a5e039ed92467e827fd3ca347fa08f19fe086fcbdd14a4ebe9c2f01
F ext/wasm/api/sqlite3-api-opfs.js 1b097808b7b081b0f0700cf97d49ef19760e401706168edff9cd45cf9169f541
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-wasm.c 336389b23c9b83763177499e49a0967949c392b2f7d84fbbb52ad6678e159f18
F ext/wasm/batch-runner.html c363032aba7a525920f61f8be112a29459f73f07e46f0ba3b7730081a617826e
F ext/wasm/sql/000-mandelbrot.sql 775337a4b80938ac8146aedf88808282f04d02d983d82675bd63d9c2d97a15f0
F ext/wasm/sql/001-sudoku.sql 35b7cb7239ba5d5f193bc05ec379bcf66891bce6f2a5b3879f2f78d0917299b5
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/test-opfs-vfs.html eb69dda21eb414b8f5e3f7c1cc0f774103cc9c0f87b2d28a33419e778abfbab5
F ext/wasm/test-opfs-vfs.js a59ff9210b17d46b0c6fbf6a0ba60143c033327865f2e556e14f06280cef62ac
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.js 5584e9b68f797dbc0f6161360f2c6840169533813d92c74d355a3e78dd5bb539
F ext/wasm/testing2.html a66951c38137ff1d687df79466351f3c734fa9c6d9cce71d3cf97c291b2167e3
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 96818aa83f4ccc574f558231249ecbdd39763b4351cf4cf6d33f53774a3ee5e6
-R 572b0ac83bec64a69d8e85421a244ded
+P c68b9aa160e2c1197ae7eb06a634017ac2b281393074afa4582762d5458c6889
+R 049b4866f034ceed644fe53d6e8f46f9
U stephan
-Z 43e7dcdb92d55bec08378952a610d517
+Z f5dc0abfcbfb5f7170f7523cda76f56b
# Remove this line to create a well-formed Fossil manifest.