Skip to content

refactor(cloud_functions): remove deprecated Task APIs #10076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.TaskCompletionSource;
import com.google.android.gms.tasks.Tasks;
import com.google.firebase.FirebaseApp;
import com.google.firebase.functions.FirebaseFunctions;
Expand Down Expand Up @@ -60,31 +61,40 @@ private FirebaseFunctions getFunctions(Map<String, Object> arguments) {
}

private Task<Object> httpsFunctionCall(Map<String, Object> arguments) {
return Tasks.call(
cachedThreadPool,
TaskCompletionSource<Object> taskCompletionSource = new TaskCompletionSource<>();

cachedThreadPool.execute(
() -> {
FirebaseFunctions firebaseFunctions = getFunctions(arguments);
try {

String functionName = (String) Objects.requireNonNull(arguments.get("functionName"));
String origin = (String) arguments.get("origin");
Integer timeout = (Integer) arguments.get("timeout");
Object parameters = arguments.get("parameters");
FirebaseFunctions firebaseFunctions = getFunctions(arguments);

if (origin != null) {
Uri originUri = Uri.parse(origin);
firebaseFunctions.useEmulator(originUri.getHost(), originUri.getPort());
}
String functionName = (String) Objects.requireNonNull(arguments.get("functionName"));
String origin = (String) arguments.get("origin");
Integer timeout = (Integer) arguments.get("timeout");
Object parameters = arguments.get("parameters");

HttpsCallableReference httpsCallableReference =
firebaseFunctions.getHttpsCallable(functionName);
if (origin != null) {
Uri originUri = Uri.parse(origin);
firebaseFunctions.useEmulator(originUri.getHost(), originUri.getPort());
}

if (timeout != null) {
httpsCallableReference.setTimeout(timeout.longValue(), TimeUnit.MILLISECONDS);
}
HttpsCallableReference httpsCallableReference =
firebaseFunctions.getHttpsCallable(functionName);

HttpsCallableResult result = Tasks.await(httpsCallableReference.call(parameters));
return result.getData();
if (timeout != null) {
httpsCallableReference.setTimeout(timeout.longValue(), TimeUnit.MILLISECONDS);
}

HttpsCallableResult result = Tasks.await(httpsCallableReference.call(parameters));
taskCompletionSource.setResult(result.getData());

} catch (Exception e) {
taskCompletionSource.setException(e);
}
});

return taskCompletionSource.getTask();
}

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

@Override
public Task<Map<String, Object>> getPluginConstantsForFirebaseApp(FirebaseApp firebaseApp) {
return Tasks.call(() -> null);
TaskCompletionSource<Map<String, Object>> taskCompletionSource = new TaskCompletionSource<>();

cachedThreadPool.execute(() -> taskCompletionSource.setResult(null));

return taskCompletionSource.getTask();
}

@Override
public Task<Void> didReinitializeFirebaseCore() {
return Tasks.call(() -> null);
TaskCompletionSource<Void> taskCompletionSource = new TaskCompletionSource<>();

cachedThreadPool.execute(() -> taskCompletionSource.setResult(null));

return taskCompletionSource.getTask();
}
}