Skip to content

Commit

Permalink
fix: infinite initialization on web
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed Mar 6, 2024
1 parent c461b99 commit 42c42ea
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ function degradePerformance(error: Error) {
/**
* Runs a piece of code and degrades performance if certain errors are thrown
*/
function tryOrDegradePerformance<T>(fn: () => Promise<T> | T): Promise<T> {
function tryOrDegradePerformance<T>(fn: () => Promise<T> | T, waitForInitialization = true): Promise<T> {
return new Promise<T>((resolve, reject) => {
initPromise.then(() => {
const promise = waitForInitialization ? initPromise : Promise.resolve();

promise.then(() => {
try {
resolve(fn());
} catch (error) {
Expand Down Expand Up @@ -61,7 +63,7 @@ const Storage: Storage = {
* and enables fallback providers if necessary
*/
init() {
tryOrDegradePerformance(provider.init).finally(() => {
tryOrDegradePerformance(provider.init, false).finally(() => {
finishInitalization();
});
},
Expand Down

0 comments on commit 42c42ea

Please sign in to comment.