diff options
author | stephan <stephan@noemail.net> | 2023-07-21 09:10:42 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2023-07-21 09:10:42 +0000 |
commit | 3068d6622e6f4def5dca4b9db8bde765fcc617bb (patch) | |
tree | 4403a01ece19d7ad84b7189b15fed194ac2298ed /ext/wasm/api/sqlite3-api-prologue.js | |
parent | 35325a37ce6dcf4b68110d39765fd441e0829ddf (diff) | |
download | sqlite-3068d6622e6f4def5dca4b9db8bde765fcc617bb.tar.gz sqlite-3068d6622e6f4def5dca4b9db8bde765fcc617bb.zip |
Internal cleanups in the async part of the JS library bootstrap phase.
FossilOrigin-Name: b6d57ab63793241a500ea527c5b3216c54b3ff1972d3adbbf42a9a53bfec0aa1
Diffstat (limited to 'ext/wasm/api/sqlite3-api-prologue.js')
-rw-r--r-- | ext/wasm/api/sqlite3-api-prologue.js | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index f2d568e2e..0179091c0 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -1889,19 +1889,9 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( */ asyncPostInit: async function ff(){ if(ff.isReady instanceof Promise) return ff.isReady; - let lip = sqlite3ApiBootstrap.initializersAsync; + let lia = sqlite3ApiBootstrap.initializersAsync; delete sqlite3ApiBootstrap.initializersAsync; - if(!lip || !lip.length){ - return ff.isReady = Promise.resolve(sqlite3); - } - lip = lip.map((f)=>{ - return (f instanceof Function) ? async x=>f(sqlite3) : f; - }); - const catcher = (e)=>{ - config.error("an async sqlite3 initializer failed:",e); - throw e; - }; - const postInit = ()=>{ + const postInit = async ()=>{ if(!sqlite3.__isUnderTest){ /* Delete references to internal-only APIs which are used by some initializers. Retain them when running in test mode @@ -1915,18 +1905,20 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( } return sqlite3; }; - if(1){ - /* Run all initializers in the sequence they were added. The - advantage is that it allows us to have post-init cleanup - defined outside of this routine at the end of the list and - have it run at a well-defined time. */ - let p = Promise.resolve(sqlite3); - while(lip.length) p = p.then(lip.shift()); - return ff.isReady = p.then(postInit).catch(catcher); - }else{ - /* Run them in an arbitrary order. */ - return ff.isReady = Promise.all(lip).then(postInit).catch(catcher); + const catcher = (e)=>{ + config.error("an async sqlite3 initializer failed:",e); + throw e; + }; + if(!lia || !lia.length){ + return ff.isReady = postInit().catch(catcher); } + lia = lia.map((f)=>{ + return (f instanceof Function) ? async x=>f(sqlite3) : f; + }); + lia.push(postInit); + let p = Promise.resolve(sqlite3); + while(lia.length) p = p.then(lia.shift()); + return ff.isReady = p.catch(catcher); }, /** scriptInfo ideally gets injected into this object by the |