1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

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
This commit is contained in:
stephan
2023-03-27 13:57:08 +00:00
parent 3594b2b303
commit fc6c3936aa
4 changed files with 32 additions and 22 deletions

View File

@ -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},