-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wait for data root before loading filesystem #42
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,8 @@ export const register = async (username: string): Promise<boolean> => { | |
} | ||
|
||
export const loadAccount = async (username: string): Promise<void> => { | ||
await checkDataRoot(username) | ||
|
||
const fs = await webnative.loadRootFileSystem() | ||
filesystemStore.set(fs) | ||
|
||
|
@@ -115,3 +117,28 @@ export const loadAccount = async (username: string): Promise<void> => { | |
authed: true | ||
})) | ||
} | ||
|
||
const checkDataRoot = async (username: string): Promise<void> => { | ||
let dataRoot = await webnative.dataRoot.lookup(username) | ||
|
||
if (dataRoot) return | ||
|
||
return new Promise((resolve) => { | ||
const maxRetries = 20 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bgins Not familiar with TypeScript module best practices, but feels weird to define this constant here. The name is quite clear! I wondering if it should be moved to the top level of Maybe we wait until we need a retry construct somewhere else? Now that I'm thinking about it, should this retry behavior be handled by the WebNative library, perhaps with an exponential backoff? (future improvement, not for this PR) |
||
let attempt = 0 | ||
|
||
const dataRootInterval = setInterval(async () => { | ||
console.warn('Could not fetch filesystem data root. Retrying.') | ||
|
||
dataRoot = await webnative.dataRoot.lookup(username) | ||
|
||
if (!dataRoot && attempt < maxRetries) { | ||
attempt++ | ||
return | ||
} | ||
|
||
clearInterval(dataRootInterval) | ||
resolve() | ||
}, 500) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard clause! 💪