1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! Demonstrates generating `Response::Stream` values using `async-stream`.
//!
//! The `stream_response` function yields five sequential frames using
//! `async_stream::try_stream`. It returns a `Response` that can be
//! consumed by a `ConnectionActor`.
use io;
use try_stream;
use StreamExt;
use info;
use Response;
/// A small serializable payload used to make stream ordering visible.
///
/// The value is deliberately just a sequence number: the example can focus on
/// the producer yielding frames and the consumer awaiting them in order rather
/// than on application-specific message handling.
;
/// Builds a response whose frames are produced lazily by an asynchronous
/// stream.
///
/// The producer yields five sequence-numbered frames and then ends. Pinning
/// the stream in the response matches the ownership contract expected by a
/// `ConnectionActor`: the actor owns polling while the response remains a
/// single value that can be returned from a handler.
/// Runs the stream consumer and logs each frame as it arrives.
///
/// Awaiting `next` one item at a time applies back-pressure, while the
/// producer's yield order determines the consumer's observed order. The loop
/// also naturally stops when the producer signals completion. This example
/// intentionally treats a stream error as
/// termination because it is illustrating response shape, not error recovery.
async