From c687a34b2be0ede050ae2b55439e218a28e92173 Mon Sep 17 00:00:00 2001 From: Weihao Ding <158090588+weihao-statsig@users.noreply.github.com> Date: Fri, 8 Nov 2024 17:10:10 -0800 Subject: [PATCH] fix: make storage provider & initialize synchronous (#305) 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? --- Sources/Statsig/Statsig.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Sources/Statsig/Statsig.swift b/Sources/Statsig/Statsig.swift index b989f55..ae79edc 100644 --- a/Sources/Statsig/Statsig.swift +++ b/Sources/Statsig/Statsig.swift @@ -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() }