Skip to content

Commit

Permalink
fix: make storage provider & initialize synchronous (#305)
Browse files Browse the repository at this point in the history
openAI reported:


The Statsig.start() API previously made Statsig available to query
feature flags as soon as it returned (because the client variable is set
synchronously).
However, when passing a storageProvider object, it now performs a
DispatchQueue.main.async call before setting client. This means that all
the checkGate() calls we make immediately after result in seeing this in
the console:
`[Statsig]: Must start Statsig first and wait for it to complete before
calling checkGate. Returning false as the default.`

I don't see a reason for this DispatchQueue.main.async . Could this be
changed so initialization is consistent whether passing storageProvider
or not?
  • Loading branch information
weihao-statsig authored Nov 9, 2024
1 parent 05dffe0 commit c687a34
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Sources/Statsig/Statsig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ public class Statsig {
_initialize()
}
} else if let storageProvider = options?.storageProvider {
DispatchQueue.main.async {
StatsigUserDefaults.defaults = StorageProviderBasedUserDefaults(storageProvider: storageProvider)
_initialize()
}
StatsigUserDefaults.defaults = StorageProviderBasedUserDefaults(storageProvider: storageProvider)
_initialize()
} else {
_initialize()
}
Expand Down

0 comments on commit c687a34

Please sign in to comment.