Created
June 28, 2019 23:41
-
-
Save phylliswong/e0fc4ebdea6a246ea76b618336c017f7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public func get<T>(key: String, defaultValue: T) -> Any { | |
let group = DispatchGroup() | |
var allocations = [JSON]() | |
var value = [JSON]() | |
if (futureAllocations == nil) { return defaultValue } | |
// This needs to be a blocking operation | |
let _ = self.futureAllocations?.done { (jsonArray) in | |
allocations = jsonArray | |
} | |
// lines 9-11 MUST be complete BEFORE the rest of this code executes | |
if !Allocator.allocationsNotEmpty(allocations: allocations) { | |
return defaultValue | |
} | |
let type = getMyType(defaultValue) | |
guard let _ = type else { return defaultValue } | |
do { | |
let alloc = Allocations(allocations: allocations) | |
let v = try alloc.getValueFromAllocations(key, type, participant) | |
if let val = v { value = val } | |
} catch { | |
LOGGER.log(.error, message: "Unable to retrieve the treatment. Returning the default.") | |
return defaultValue | |
} | |
return value | |
} |
let a = try futureAllocations?.wait()
Where is futureAllocations
defined?
let a = try futureAllocations?.wait()
Where is
futureAllocations
defined?
This gets initialized by the Allocator class's fetch method. When the client gets initialized, the value is a promise. Then when the promise is fulfilled ... after .wait() then I can perform the other tasks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got the solution...it was waaaaay easier than I was making it.