Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 36 additions & 8 deletions LaunchDarkly/LaunchDarkly/LDClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ public class LDClient {
instance.internalSetOnline(goOnline, completion: dispatch.leave)
}
}
if let completion = completion {
dispatch.notify(queue: DispatchQueue.global(), execute: completion)
if let completion {
dispatch.notify(queue: .main) {
completion()
}
}
}

Expand Down Expand Up @@ -292,7 +294,9 @@ public class LDClient {
public func identify(context: LDContext, completion: (() -> Void)? = nil) {
_identifyHooked(context: context, sheddable: false, useCache: .yes, timeout: 0) { _ in
if let completion = completion {
completion()
DispatchQueue.main.async {
completion()
}
}
}
}
Expand All @@ -313,7 +317,11 @@ public class LDClient {
- parameter completion: Closure called when the embedded `setOnlineIdentify` call completes, subject to throttling delays.
*/
public func identify(context: LDContext, completion: @escaping (_ result: IdentifyResult) -> Void) {
_identifyHooked(context: context, sheddable: true, useCache: .yes, timeout: 0, completion: completion)
_identifyHooked(context: context, sheddable: true, useCache: .yes, timeout: 0) { result in
DispatchQueue.main.async {
completion(result)
}
}
}

/**
Expand All @@ -327,7 +335,11 @@ public class LDClient {
- parameter completion: Closure called when the embedded `setOnlineIdentify` call completes, subject to throttling delays.
*/
public func identify(context: LDContext, useCache: IdentifyCacheUsage, completion: @escaping (_ result: IdentifyResult) -> Void) {
_identifyHooked(context: context, sheddable: true, useCache: useCache, timeout: 0, completion: completion)
_identifyHooked(context: context, sheddable: true, useCache: useCache, timeout: 0) { result in
DispatchQueue.main.async {
completion(result)
}
}
}

// Temporary helper method to allow code sharing between the sheddable and unsheddable identify methods. In the next major release, we will remove the deprecated identify method and inline
Expand Down Expand Up @@ -385,7 +397,11 @@ public class LDClient {
os_log("%s LDClient.identify was called with a timeout greater than %f seconds. We recommend a timeout of less than %f seconds.", log: config.logger, type: .info, self.typeName(and: #function), LDClient.longTimeoutInterval, LDClient.longTimeoutInterval)
}

self._identifyHooked(context: context, sheddable: true, useCache: useCache, timeout: timeout, completion: completion)
self._identifyHooked(context: context, sheddable: true, useCache: useCache, timeout: timeout) { result in
DispatchQueue.main.async {
completion(result)
}
}
}

func internalIdentify(newContext: LDContext, useCache: IdentifyCacheUsage, completion: (() -> Void)? = nil) {
Expand Down Expand Up @@ -741,7 +757,13 @@ public class LDClient {
/// - Tag: start
@available(*, deprecated, message: "Use LDClient.start(config: context: startWithSeconds: completion:) to initialize the SDK with a defined timeout")
public static func start(config: LDConfig, context: LDContext? = nil, completion: (() -> Void)? = nil) {
start(serviceFactory: nil, config: config, context: context, completion: completion)
start(serviceFactory: nil, config: config, context: context) {
if let completion {
DispatchQueue.main.async {
completion()
}
}
}
}

static func start(serviceFactory: ClientServiceCreating?, config: LDConfig, context: LDContext? = nil, completion: (() -> Void)? = nil) {
Expand Down Expand Up @@ -836,7 +858,13 @@ public class LDClient {
os_log("%s LDClient.start was called with a timeout greater than %f seconds. We recommend a timeout of less than %f seconds.", log: config.logger, type: .info, self.typeName(and: #function), LDClient.longTimeoutInterval, LDClient.longTimeoutInterval)
}

start(serviceFactory: nil, config: config, context: context, startWaitSeconds: startWaitSeconds, completion: completion)
start(serviceFactory: nil, config: config, context: context, startWaitSeconds: startWaitSeconds) { timedOut in
if let completion {
DispatchQueue.main.async {
completion(timedOut)
}
}
}
}

static func start(serviceFactory: ClientServiceCreating?, config: LDConfig, context: LDContext? = nil, startWaitSeconds: TimeInterval, completion: ((_ timedOut: Bool) -> Void)? = nil) {
Expand Down