-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent duplicate
v1/configuration
GET requests (#1363)
- Loading branch information
Showing
5 changed files
with
74 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Foundation | ||
|
||
/// Used to store, access, and manage an array of to-be-invoked `BTConfiguration` GET result callbacks in a thread-safe manner | ||
class ConfigurationCallbackStorage { | ||
|
||
private let queue = DispatchQueue(label: "com.braintreepayments.ConfigurationCallbackStorage") | ||
private var pendingCompletions: [(BTConfiguration?, Error?) -> Void] = [] | ||
|
||
/// The number of completions that are waiting to be invoked | ||
var count: Int { | ||
queue.sync { pendingCompletions.count } | ||
} | ||
|
||
/// Adds a pending, yet to-be-invoked completion handler | ||
func add(_ completion: @escaping (BTConfiguration?, Error?) -> Void) { | ||
queue.sync { pendingCompletions.append(completion) } | ||
} | ||
|
||
/// Executes and clears all pending completion handlers | ||
func invoke(_ configuration: BTConfiguration?, _ error: Error?) { | ||
queue.sync { | ||
pendingCompletions.forEach { $0(configuration, error) } | ||
pendingCompletions.removeAll() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters