-
Notifications
You must be signed in to change notification settings - Fork 596
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
feat(functions): add streamAsFlow() for convenience #6774
Open
thatfiredev
wants to merge
2
commits into
main
Choose a base branch
from
rpf/functions-stream-asflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Javadoc Changes:--- /home/runner/diff/original/firebase-kotlindoc/android/com/google/firebase/functions/HttpsCallableReference.html 2025-03-14 14:17:09.174318372 +0000
+++ /home/runner/diff/modified/firebase-kotlindoc/android/com/google/firebase/functions/HttpsCallableReference.html 2025-03-14 14:14:15.214219952 +0000
@@ -75,6 +75,13 @@
</td>
</tr>
<tr>
+ <td><code>final @<a href="https://developer.android.com/reference/kotlin/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html">Flow</a><@<a href="https://developer.android.com/reference/kotlin/androidx/annotation/NonNull.html">NonNull</a> <a href="/docs/reference/android/com/google/firebase/functions/StreamResponse.html">StreamResponse</a>></code></td>
+ <td>
+ <div><code><a href="/docs/reference/android/com/google/firebase/functions/HttpsCallableReference.html#streamAsFlow(kotlin.Any)">streamAsFlow</a>(<a href="https://developer.android.com/reference/kotlin/java/lang/Object.html">Object</a> data)</code></div>
+ <p>Streams data to the specified HTTPS endpoint.</p>
+ </td>
+ </tr>
+ <tr>
<td><code>final @<a href="https://developer.android.com/reference/kotlin/androidx/annotation/NonNull.html">NonNull</a> <a href="/docs/reference/android/com/google/firebase/functions/HttpsCallableReference.html">HttpsCallableReference</a></code></td>
<td>
<div><code><a href="/docs/reference/android/com/google/firebase/functions/HttpsCallableReference.html#withTimeout(kotlin.Long,java.util.concurrent.TimeUnit)">withTimeout</a>(long timeout, @<a href="https://developer.android.com/reference/kotlin/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/kotlin/java/util/concurrent/TimeUnit.html">TimeUnit</a> units)</code></div>
@@ -369,6 +376,131 @@
</td>
</tr>
</tbody>
+ </table>
+ </div>
+ <div class="devsite-table-wrapper">
+ <table class="responsive">
+ <colgroup>
+ <col width="40%">
+ <col>
+ </colgroup>
+ <thead>
+ <tr>
+ <th colspan="100%">See also</th>
+ </tr>
+ </thead>
+ <tbody class="list">
+ <tr>
+ <td><code><a href="https://developer.android.com/reference/kotlin/org/json/JSONArray.html">JSONArray</a></code></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td><code><a href="https://developer.android.com/reference/kotlin/org/json/JSONObject.html">JSONObject</a></code></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td><code><a href="https://developer.android.com/reference/kotlin/java/io/IOException.html">IOException</a></code></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td><code><a href="/docs/reference/android/com/google/firebase/functions/FirebaseFunctionsException.html">FirebaseFunctionsException</a></code></td>
+ <td></td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </div>
+ <div class="api-item"><a name="streamAsFlow-kotlin.Any-"></a><a name="streamasflow"></a>
+ <h3 class="api-name" id="streamAsFlow(kotlin.Any)">streamAsFlow</h3>
+ <pre class="api-signature no-pretty-print">public final @<a href="https://developer.android.com/reference/kotlin/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html">Flow</a><@<a href="https://developer.android.com/reference/kotlin/androidx/annotation/NonNull.html">NonNull</a> <a href="/docs/reference/android/com/google/firebase/functions/StreamResponse.html">StreamResponse</a>> <a href="/docs/reference/android/com/google/firebase/functions/HttpsCallableReference.html#streamAsFlow(kotlin.Any)">streamAsFlow</a>(<a href="https://developer.android.com/reference/kotlin/java/lang/Object.html">Object</a> data)</pre>
+ <p>Streams data to the specified HTTPS endpoint.</p>
+ <p>The data passed into the trigger can be any of the following types:</p>
+ <ul>
+ <li>
+ <p>Any primitive type, including null, int, long, float, and boolean.</p>
+ </li>
+ <li>
+ <p><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html">String</a></code></p>
+ </li>
+ <li>
+ <p><code><a href="https://developer.android.com/reference/kotlin/java/util/List.html">List</a></code>, where the contained objects are also one of these types.</p>
+ </li>
+ <li>
+ <p><code><a href="https://developer.android.com/reference/kotlin/java/util/Map.html">Map</a></code>, where the values are also one of these types.</p>
+ </li>
+ <li>
+ <p><code><a href="https://developer.android.com/reference/kotlin/org/json/JSONArray.html">org.json.JSONArray</a></code></p>
+ </li>
+ <li>
+ <p><code><a href="https://developer.android.com/reference/kotlin/org/json/JSONObject.html">org.json.JSONObject</a></code></p>
+ </li>
+ <li>
+ <p><code><a href="https://developer.android.com/reference/kotlin/org/json/JSONObject.html#NULL--">org.json.JSONObject.NULL</a></code></p>
+ </li>
+ </ul>
+ <p>If the returned streamResponse fails, the exception will be one of the following types:</p>
+ <ul>
+ <li>
+ <p><code><a href="https://developer.android.com/reference/kotlin/java/io/IOException.html">java.io.IOException</a></code></p>
+ </li>
+ </ul>
+ <ul>
+ <li>
+ <p>if the HTTPS request failed to connect.</p>
+ </li>
+ </ul>
+ <ul>
+ <li>
+ <p><code><a href="/docs/reference/android/com/google/firebase/functions/FirebaseFunctionsException.html">FirebaseFunctionsException</a></code></p>
+ </li>
+ </ul>
+ <ul>
+ <li>
+ <p>if the request connected, but the function returned an error.</p>
+ </li>
+ </ul>
+ <p>The request to the Cloud Functions backend made by this method automatically includes a Firebase Instance ID token to identify the app instance. If a user is logged in with Firebase Auth, an auth token for the user will also be automatically included.</p>
+ <p>Firebase Instance ID sends data to the Firebase backend periodically to collect information regarding the app instance. To stop this, see <code><a href="/docs/reference/android/com/google/firebase/iid/FirebaseInstanceId.html#deleteInstanceId()">com.google.firebase.iid.FirebaseInstanceId.deleteInstanceId</a></code>. It will resume with a new Instance ID the next time you call this method.</p>
+ <div class="devsite-table-wrapper">
+ <table class="responsive">
+ <colgroup>
+ <col width="40%">
+ <col>
+ </colgroup>
+ <thead>
+ <tr>
+ <th colspan="100%">Parameters</th>
+ </tr>
+ </thead>
+ <tbody class="list">
+ <tr>
+ <td><code><a href="https://developer.android.com/reference/kotlin/java/lang/Object.html">Object</a> data</code></td>
+ <td>
+ <p>Parameters to pass to the endpoint. Defaults to <code>null</code> if not provided.</p>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div class="devsite-table-wrapper">
+ <table class="responsive">
+ <colgroup>
+ <col width="40%">
+ <col>
+ </colgroup>
+ <thead>
+ <tr>
+ <th colspan="100%">Returns</th>
+ </tr>
+ </thead>
+ <tbody class="list">
+ <tr>
+ <td><code>@<a href="https://developer.android.com/reference/kotlin/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html">Flow</a><@<a href="https://developer.android.com/reference/kotlin/androidx/annotation/NonNull.html">NonNull</a> <a href="/docs/reference/android/com/google/firebase/functions/StreamResponse.html">StreamResponse</a>></code></td>
+ <td>
+ <p><code><a href="https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html">Flow</a></code> that will emit intermediate data, and the final result, as it is generated by the function.</p>
+ </td>
+ </tr>
+ </tbody>
</table>
</div>
<div class="devsite-table-wrapper"> --- /home/runner/diff/original/firebase-kotlindoc/kotlin/com/google/firebase/functions/HttpsCallableReference.html 2025-03-14 14:17:09.165318367 +0000
+++ /home/runner/diff/modified/firebase-kotlindoc/kotlin/com/google/firebase/functions/HttpsCallableReference.html 2025-03-14 14:14:15.199219945 +0000
@@ -54,6 +54,13 @@
</td>
</tr>
<tr>
+ <td><code><a href="https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html">Flow</a><<a href="/docs/reference/kotlin/com/google/firebase/functions/StreamResponse.html">StreamResponse</a>></code></td>
+ <td>
+ <div><code><a href="/docs/reference/kotlin/com/google/firebase/functions/HttpsCallableReference.html#streamAsFlow(kotlin.Any)">streamAsFlow</a>(data: <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>?)</code></div>
+ <p>Streams data to the specified HTTPS endpoint.</p>
+ </td>
+ </tr>
+ <tr>
<td><code><a href="/docs/reference/kotlin/com/google/firebase/functions/HttpsCallableReference.html">HttpsCallableReference</a></code></td>
<td>
<div><code><a href="/docs/reference/kotlin/com/google/firebase/functions/HttpsCallableReference.html#withTimeout(kotlin.Long,java.util.concurrent.TimeUnit)">withTimeout</a>(timeout: <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html">Long</a>, units: <a href="https://developer.android.com/reference/kotlin/java/util/concurrent/TimeUnit.html">TimeUnit</a>)</code></div>
@@ -362,6 +369,131 @@
</td>
</tr>
</tbody>
+ </table>
+ </div>
+ <div class="devsite-table-wrapper">
+ <table class="responsive">
+ <colgroup>
+ <col width="40%">
+ <col>
+ </colgroup>
+ <thead>
+ <tr>
+ <th colspan="100%">See also</th>
+ </tr>
+ </thead>
+ <tbody class="list">
+ <tr>
+ <td><code><a href="https://developer.android.com/reference/kotlin/org/json/JSONArray.html">JSONArray</a></code></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td><code><a href="https://developer.android.com/reference/kotlin/org/json/JSONObject.html">JSONObject</a></code></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td><code><a href="https://developer.android.com/reference/kotlin/java/io/IOException.html">IOException</a></code></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td><code><a href="/docs/reference/kotlin/com/google/firebase/functions/FirebaseFunctionsException.html">FirebaseFunctionsException</a></code></td>
+ <td></td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </div>
+ <div class="api-item"><a name="streamAsFlow-kotlin.Any-"></a><a name="streamasflow"></a>
+ <h3 class="api-name" id="streamAsFlow(kotlin.Any)">streamAsFlow</h3>
+ <pre class="api-signature no-pretty-print">fun <a href="/docs/reference/kotlin/com/google/firebase/functions/HttpsCallableReference.html#streamAsFlow(kotlin.Any)">streamAsFlow</a>(data: <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>? = null): <a href="https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html">Flow</a><<a href="/docs/reference/kotlin/com/google/firebase/functions/StreamResponse.html">StreamResponse</a>></pre>
+ <p>Streams data to the specified HTTPS endpoint.</p>
+ <p>The data passed into the trigger can be any of the following types:</p>
+ <ul>
+ <li>
+ <p>Any primitive type, including null, int, long, float, and boolean.</p>
+ </li>
+ <li>
+ <p><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html">String</a></code></p>
+ </li>
+ <li>
+ <p><code><a href="https://developer.android.com/reference/kotlin/java/util/List.html">List</a></code>, where the contained objects are also one of these types.</p>
+ </li>
+ <li>
+ <p><code><a href="https://developer.android.com/reference/kotlin/java/util/Map.html">Map</a></code>, where the values are also one of these types.</p>
+ </li>
+ <li>
+ <p><code><a href="https://developer.android.com/reference/kotlin/org/json/JSONArray.html">org.json.JSONArray</a></code></p>
+ </li>
+ <li>
+ <p><code><a href="https://developer.android.com/reference/kotlin/org/json/JSONObject.html">org.json.JSONObject</a></code></p>
+ </li>
+ <li>
+ <p><code><a href="https://developer.android.com/reference/kotlin/org/json/JSONObject.html#NULL--">org.json.JSONObject.NULL</a></code></p>
+ </li>
+ </ul>
+ <p>If the returned streamResponse fails, the exception will be one of the following types:</p>
+ <ul>
+ <li>
+ <p><code><a href="https://developer.android.com/reference/kotlin/java/io/IOException.html">java.io.IOException</a></code></p>
+ </li>
+ </ul>
+ <ul>
+ <li>
+ <p>if the HTTPS request failed to connect.</p>
+ </li>
+ </ul>
+ <ul>
+ <li>
+ <p><code><a href="/docs/reference/kotlin/com/google/firebase/functions/FirebaseFunctionsException.html">FirebaseFunctionsException</a></code></p>
+ </li>
+ </ul>
+ <ul>
+ <li>
+ <p>if the request connected, but the function returned an error.</p>
+ </li>
+ </ul>
+ <p>The request to the Cloud Functions backend made by this method automatically includes a Firebase Instance ID token to identify the app instance. If a user is logged in with Firebase Auth, an auth token for the user will also be automatically included.</p>
+ <p>Firebase Instance ID sends data to the Firebase backend periodically to collect information regarding the app instance. To stop this, see <code><a href="/docs/reference/kotlin/com/google/firebase/iid/FirebaseInstanceId.html#deleteInstanceId()">com.google.firebase.iid.FirebaseInstanceId.deleteInstanceId</a></code>. It will resume with a new Instance ID the next time you call this method.</p>
+ <div class="devsite-table-wrapper">
+ <table class="responsive">
+ <colgroup>
+ <col width="40%">
+ <col>
+ </colgroup>
+ <thead>
+ <tr>
+ <th colspan="100%">Parameters</th>
+ </tr>
+ </thead>
+ <tbody class="list">
+ <tr>
+ <td><code>data: <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>? = null</code></td>
+ <td>
+ <p>Parameters to pass to the endpoint. Defaults to <code>null</code> if not provided.</p>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div class="devsite-table-wrapper">
+ <table class="responsive">
+ <colgroup>
+ <col width="40%">
+ <col>
+ </colgroup>
+ <thead>
+ <tr>
+ <th colspan="100%">Returns</th>
+ </tr>
+ </thead>
+ <tbody class="list">
+ <tr>
+ <td><code><a href="https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html">Flow</a><<a href="/docs/reference/kotlin/com/google/firebase/functions/StreamResponse.html">StreamResponse</a>></code></td>
+ <td>
+ <p><code><a href="https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html">Flow</a></code> that will emit intermediate data, and the final result, as it is generated by the function.</p>
+ </td>
+ </tr>
+ </tbody>
</table>
</div>
<div class="devsite-table-wrapper"> |
Generated by 🚫 Danger |
Coverage Report 1Affected Products
Test Logs |
Size Report 1Affected Products
Test Logs |
emilypgoogle
approved these changes
Mar 14, 2025
The alternative solution sounds good too. We can probably mix them by exporting reactive streams as api, as it should, and using the asflow with the library underneath |
gubatron
pushed a commit
to gubatron/firebase-android-sdk
that referenced
this pull request
Mar 24, 2025
…irebase#6775) Alternative to firebase#6774 - we'll keep that PR for a follow-up release. For now, we're exposing the `reactive-streams` dependency to make sure it works out of the box for Java developers.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For developers using Kotlin, a simple call to a streaming function (eg.
functions.getHttpsCallable("streaming").stream().asFlow()
) requires them to add the following dependencies to their build.gradle(.kts) file:This is an extra step that I think we should avoid, considering we're moving to a Kotlin-first SDK.
This PR addresses that by introducing a new
streamAsFlow()
function that Kotlin developers can call without the for the extra dependencies.Alternative solution
An alternative would be to expose these libraries in our SDK as transitive dependencies so that developers don't have to add them to their apps: