Skip to content

Commit 951bc77

Browse files
authored
refactor(cloud_functions): remove deprecated Task APIs (#10076)
1 parent d4c27da commit 951bc77

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

packages/cloud_functions/cloud_functions/android/src/main/java/io/flutter/plugins/firebase/functions/FlutterFirebaseFunctionsPlugin.java

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import androidx.annotation.NonNull;
99
import androidx.annotation.Nullable;
1010
import com.google.android.gms.tasks.Task;
11+
import com.google.android.gms.tasks.TaskCompletionSource;
1112
import com.google.android.gms.tasks.Tasks;
1213
import com.google.firebase.FirebaseApp;
1314
import com.google.firebase.functions.FirebaseFunctions;
@@ -60,31 +61,40 @@ private FirebaseFunctions getFunctions(Map<String, Object> arguments) {
6061
}
6162

6263
private Task<Object> httpsFunctionCall(Map<String, Object> arguments) {
63-
return Tasks.call(
64-
cachedThreadPool,
64+
TaskCompletionSource<Object> taskCompletionSource = new TaskCompletionSource<>();
65+
66+
cachedThreadPool.execute(
6567
() -> {
66-
FirebaseFunctions firebaseFunctions = getFunctions(arguments);
68+
try {
6769

68-
String functionName = (String) Objects.requireNonNull(arguments.get("functionName"));
69-
String origin = (String) arguments.get("origin");
70-
Integer timeout = (Integer) arguments.get("timeout");
71-
Object parameters = arguments.get("parameters");
70+
FirebaseFunctions firebaseFunctions = getFunctions(arguments);
7271

73-
if (origin != null) {
74-
Uri originUri = Uri.parse(origin);
75-
firebaseFunctions.useEmulator(originUri.getHost(), originUri.getPort());
76-
}
72+
String functionName = (String) Objects.requireNonNull(arguments.get("functionName"));
73+
String origin = (String) arguments.get("origin");
74+
Integer timeout = (Integer) arguments.get("timeout");
75+
Object parameters = arguments.get("parameters");
7776

78-
HttpsCallableReference httpsCallableReference =
79-
firebaseFunctions.getHttpsCallable(functionName);
77+
if (origin != null) {
78+
Uri originUri = Uri.parse(origin);
79+
firebaseFunctions.useEmulator(originUri.getHost(), originUri.getPort());
80+
}
8081

81-
if (timeout != null) {
82-
httpsCallableReference.setTimeout(timeout.longValue(), TimeUnit.MILLISECONDS);
83-
}
82+
HttpsCallableReference httpsCallableReference =
83+
firebaseFunctions.getHttpsCallable(functionName);
8484

85-
HttpsCallableResult result = Tasks.await(httpsCallableReference.call(parameters));
86-
return result.getData();
85+
if (timeout != null) {
86+
httpsCallableReference.setTimeout(timeout.longValue(), TimeUnit.MILLISECONDS);
87+
}
88+
89+
HttpsCallableResult result = Tasks.await(httpsCallableReference.call(parameters));
90+
taskCompletionSource.setResult(result.getData());
91+
92+
} catch (Exception e) {
93+
taskCompletionSource.setException(e);
94+
}
8795
});
96+
97+
return taskCompletionSource.getTask();
8898
}
8999

90100
@Override
@@ -156,11 +166,19 @@ private Map<String, Object> getExceptionDetails(@Nullable Exception exception) {
156166

157167
@Override
158168
public Task<Map<String, Object>> getPluginConstantsForFirebaseApp(FirebaseApp firebaseApp) {
159-
return Tasks.call(() -> null);
169+
TaskCompletionSource<Map<String, Object>> taskCompletionSource = new TaskCompletionSource<>();
170+
171+
cachedThreadPool.execute(() -> taskCompletionSource.setResult(null));
172+
173+
return taskCompletionSource.getTask();
160174
}
161175

162176
@Override
163177
public Task<Void> didReinitializeFirebaseCore() {
164-
return Tasks.call(() -> null);
178+
TaskCompletionSource<Void> taskCompletionSource = new TaskCompletionSource<>();
179+
180+
cachedThreadPool.execute(() -> taskCompletionSource.setResult(null));
181+
182+
return taskCompletionSource.getTask();
165183
}
166184
}

0 commit comments

Comments
 (0)