Skip to content

Commit

Permalink
fix: remove precondition() from BTKClient
Browse files Browse the repository at this point in the history
  • Loading branch information
duyhungtnn committed Jul 25, 2023
1 parent aedde4e commit d87adc6
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Bucketeer/Sources/Public/BKTClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ public class BKTClient {
}

extension BKTClient {
public static func initialize(config: BKTConfig, user: BKTUser, timeoutMillis: Int64 = 5000, completion: ((BKTError?) -> Void)? = nil) {
precondition(Thread.isMainThread, "the initialize method must be called on main thread")
public static func initialize(config: BKTConfig, user: BKTUser, timeoutMillis: Int64 = 5000, completion: ((BKTError?) -> Void)? = nil) throws {
guard (Thread.isMainThread) else {
throw BKTError.illegalState(message: "the initialize method must be called on main thread")
}
concurrentQueue.sync {
guard BKTClient.default == nil else {
config.logger?.warn(message: "BKTClient is already initialized. Not sure if the initial fetch has finished")
Expand All @@ -98,22 +100,23 @@ extension BKTClient {
}
}

public static func destroy() {
precondition(Thread.isMainThread, "the destroy method must be called on main thread")
public static func destroy() throws {
guard (Thread.isMainThread) else {
throw BKTError.illegalState(message: "the destroy method must be called on main thread")
}
BKTClient.default?.resetTasks()
BKTClient.default = nil
}

public static var shared: BKTClient {
get throws {
// We do not want to crash the SDK's consumer app on runtime by using fatalError().
// So let the app has a chance to catch this exception
// The same behavior with the Android SDK
guard BKTClient.default != nil else {
throw BKTError.illegalState(message: "BKTClient is not initialized")
}
return BKTClient.default
// We do not want to crash the SDK's consumer app on runtime by using fatalError().
// So let the app has a chance to catch this exception
// The same behavior with the Android SDK

}
}

Expand Down

0 comments on commit d87adc6

Please sign in to comment.