Skip to content

Commit 6a87840

Browse files
committed
add blocking async api
1 parent 2da0445 commit 6a87840

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

android-sdk/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ dependencies {
100100
androidTestImplementation "com.noveogroup.android:android-logger:$android_logger_ver"
101101
androidTestImplementation "com.google.code.gson:gson:$gson_ver"
102102
androidTestImplementation "com.fasterxml.jackson.core:jackson-databind:$jacksonversion"
103-
103+
104104
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
105105
}
106106

android-sdk/src/main/java/com/optimizely/ab/android/sdk/OptimizelyUserContextAndroid.java

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public Map<String, OptimizelyDecision> decideAll() {
155155
}
156156

157157
// ===========================================
158-
// Async Methods (Android-specific)
158+
// Async Methods (Android-specific) with callbacks
159159
// ===========================================
160160

161161
/**
@@ -224,6 +224,69 @@ public void decideAllAsync(@NonNull OptimizelyDecisionsCallback callback) {
224224
decideAllAsync(Collections.emptyList(), callback);
225225
}
226226

227+
// ===========================================
228+
// Async Methods (Android-specific) with blocking calls to synchronous methods
229+
// ===========================================
230+
231+
public OptimizelyDecision decideAsync(@Nonnull String key,
232+
@Nonnull List<OptimizelyDecideOption> options) {
233+
return super.decide(key, options);
234+
}
235+
236+
/**
237+
* Returns a decision result ({@link OptimizelyDecision}) for a given flag key and a user context, which contains all data required to deliver the flag.
238+
*
239+
* @param key A flag key for which a decision will be made.
240+
* @return A decision result.
241+
*/
242+
public OptimizelyDecision decideAsync(@Nonnull String key) {
243+
return decideAsync(key, Collections.emptyList());
244+
}
245+
246+
/**
247+
* Returns a key-map of decision results ({@link OptimizelyDecision}) for multiple flag keys and a user context.
248+
* <ul>
249+
* <li>If the SDK finds an error for a key, the response will include a decision for the key showing <b>reasons</b> for the error.
250+
* <li>The SDK will always return key-mapped decisions. When it can not process requests, it’ll return an empty map after logging the errors.
251+
* </ul>
252+
* @param keys A list of flag keys for which decisions will be made.
253+
* @param options A list of options for decision-making.
254+
* @return All decision results mapped by flag keys.
255+
*/
256+
public Map<String, OptimizelyDecision> decideForKeysAsync(@Nonnull List<String> keys,
257+
@Nonnull List<OptimizelyDecideOption> options) {
258+
return super.decideForKeys(keys, options);
259+
}
260+
261+
/**
262+
* Returns a key-map of decision results for multiple flag keys and a user context.
263+
*
264+
* @param keys A list of flag keys for which decisions will be made.
265+
* @return All decision results mapped by flag keys.
266+
*/
267+
public Map<String, OptimizelyDecision> decideForKeysAsync(@Nonnull List<String> keys) {
268+
return decideForKeysAsync(keys, Collections.emptyList());
269+
}
270+
271+
/**
272+
* Returns a key-map of decision results ({@link OptimizelyDecision}) for all active flag keys.
273+
*
274+
* @param options A list of options for decision-making.
275+
* @return All decision results mapped by flag keys.
276+
*/
277+
public Map<String, OptimizelyDecision> decideAllAsync(@Nonnull List<OptimizelyDecideOption> options) {
278+
return super.decideAll(options);
279+
}
280+
281+
/**
282+
* Returns a key-map of decision results ({@link OptimizelyDecision}) for all active flag keys.
283+
*
284+
* @return A dictionary of all decision results, mapped by flag keys.
285+
*/
286+
public Map<String, OptimizelyDecision> decideAllAsync() {
287+
return decideAllAsync(Collections.emptyList());
288+
}
289+
227290
// ===========================================
228291
// Override methods for testability
229292
// These methods enable Mockito spies to intercept calls that would

0 commit comments

Comments
 (0)