Skip to content

Commit 2ea5c80

Browse files
committed
snippetize client
1 parent 254bfb7 commit 2ea5c80

File tree

1 file changed

+21
-6
lines changed
  • Node/quickstarts/callable-functions-streaming/website

1 file changed

+21
-6
lines changed

Node/quickstarts/callable-functions-streaming/website/index.html

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
const app = initializeApp(firebaseConfig);
2828
const functions = getFunctions(app);
2929
connectFunctionsEmulator(functions, "127.0.0.1", 5001);
30-
const getForecast = httpsCallable(functions, "getForecast");
30+
3131

3232
const favoriteLocations = [
3333
// Google HQ
@@ -36,20 +36,35 @@
3636
{ latitude: 37.745192257741984, longitude: -119.5945133017153 },
3737
// Old Faithful
3838
{ latitude: 44.46037818049411, longitude: -110.82802255265777 },
39-
]
39+
];
4040

4141
async function handleClick() {
4242
// reset result
4343
clearUi();
4444

45-
const resp = await getForecast.stream({
45+
// [START stream_data_client]
46+
// Get the callable by passing an initialized functions SDK.
47+
const getForecast = httpsCallable(functions, "getForecast");
48+
49+
// Call the function with the `.stream()` method to start streaming.
50+
const {stream, data} = await getForecast.stream({
4651
locations: favoriteLocations,
4752
});
4853

49-
// loop through the `stream` async iterable
50-
for await (const forecastData of resp.stream) {
51-
updateUi(forecastData);
54+
// The `stream` async iterable returned by `.stream()`
55+
// will yield a new value every time the callable
56+
// function calls `sendChunk()`.
57+
for await (const forecastDataChunk of stream) {
58+
// update the UI every time a new chunk is received
59+
// from the callable function
60+
updateUi(forecastDataChunk);
5261
}
62+
63+
// The `data` promise resolves when the callable
64+
// function completes.
65+
const allWeatherForecasts = await data;
66+
finalizeUi(allWeatherForecasts);
67+
// [END stream_data_client]
5368
}
5469

5570
function clearUi() {

0 commit comments

Comments
 (0)