aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2023-03-27 13:57:08 +0000
committerstephan <stephan@noemail.net>2023-03-27 13:57:08 +0000
commitfc6c3936aac93d7c47c2780b0254422737a23090 (patch)
tree96b90dcd48a5c61ad0692e2c9bca65df3a7f4f5d /ext/wasm/api/sqlite3-vfs-opfs.c-pp.js
parent3594b2b3031ce0239ddedbd2c2b0367cf51b56ed (diff)
downloadsqlite-fc6c3936aac93d7c47c2780b0254422737a23090.tar.gz
sqlite-fc6c3936aac93d7c47c2780b0254422737a23090.zip
Remove a meaningless JS test. Add a timer to the OPFS async-side worker loader in an attempt to catch a browser-specific quirk in which the worker loading silently fails, per discussion in/around [forum post a708c98dcb3ef|forum:a708c98dcb3ef].
FossilOrigin-Name: 4fc1904b8e18c7d41fa65490ced125f1df4f0c22c13de957b24615ed09b3ecb7
Diffstat (limited to 'ext/wasm/api/sqlite3-vfs-opfs.c-pp.js')
-rw-r--r--ext/wasm/api/sqlite3-vfs-opfs.c-pp.js25
1 files changed, 23 insertions, 2 deletions
diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js
index 09f7f8bdb..e9dfcf417 100644
--- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js
+++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js
@@ -117,7 +117,7 @@ const installOpfsVfs = function callee(options){
if('function' === typeof options.proxyUri){
options.proxyUri = options.proxyUri();
}
- const thePromise = new Promise(function(promiseResolve, promiseReject_){
+ const thePromise = new Promise(function(promiseResolve_, promiseReject_){
const loggers = {
0:sqlite3.config.error,
1:sqlite3.config.warn,
@@ -193,10 +193,16 @@ const installOpfsVfs = function callee(options){
}/*metrics*/;
const opfsVfs = new sqlite3_vfs();
const opfsIoMethods = new sqlite3_io_methods();
- const promiseReject = function(err){
+ let promiseWasRejected = undefined;
+ const promiseReject = (err)=>{
+ promiseWasRejected = true;
opfsVfs.dispose();
return promiseReject_(err);
};
+ const promiseResolve = (value)=>{
+ promiseWasRejected = false;
+ return promiseResolve_(value);
+ };
const W =
//#if target=es6-bundler-friendly
new Worker(new URL("sqlite3-opfs-async-proxy.js", import.meta.url));
@@ -205,6 +211,18 @@ const installOpfsVfs = function callee(options){
//#else
new Worker(options.proxyUri);
//#endif
+ setTimeout(()=>{
+ /* At attempt to work around a browser-specific quirk in which
+ the Worker load is failing in such a way that we neither
+ resolve nor reject it. This workaround gives that resolve/reject
+ a time limit and rejects if that timer expires. Discussion:
+ https://sqlite.org/forum/forumpost/a708c98dcb3ef */
+ if(undefined===promiseWasRejected){
+ promiseReject(
+ new Error("Timeout while waiting for OPFS async proxy worker.")
+ );
+ }
+ }, 4000);
W._originalOnError = W.onerror /* will be restored later */;
W.onerror = function(err){
// The error object doesn't contain any useful info when the
@@ -1269,6 +1287,9 @@ const installOpfsVfs = function callee(options){
/*Indicates that the async partner has received the 'init'
and has finished initializing, so the real work can
begin...*/
+ if(true===promiseWasRejected){
+ break /* promise was already rejected via timer */;
+ }
try {
sqlite3.vfs.installVfs({
io: {struct: opfsIoMethods, methods: ioSyncWrappers},