Skip to content

Enable a Way to Await User Details Loading #94

@PSchmiedmayer

Description

@PSchmiedmayer

Problem

Accessing the account details can sometimes result in nil values despite them being available a few milliseconds later while the Account module is loading data. E.g., in the PAWS app we have the following code to access a user detail value:

// Waiting until Spezi Account loads the account details.
let loadingStartDate = Date.now
while await account?.details?.dateOfEnrollment == nil && abs(loadingStartDate.distance(to: .now)) < 0.5 {
    logger.debug("Loading DateOfEnrollment ...")
    try await Task.sleep(for: .seconds(0.02))
}

Solution

Ideally we would have a way to either await for the initial loading or even a blocking mechanism that would temporarily lock/block access to the details until the initial loading is complete to enable a sync access to the properties. Otherwise it is required to use a construct like the code shared above to access option account details to determine if they are nil or not yet loaded.

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct and Contributing Guidelines

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or request

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions