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
// SPDX-License-Identifier: Apache-2.0
//! scope\_channel — producer/consumer inside a scoped goroutine pair.
//!
//! `go_lib::scope` lets you pair goroutines that communicate over a channel
//! while still getting the scope's lifetime guarantee: both goroutines finish
//! before `scope` returns, so no `Arc` or `WaitGroup` is needed to coordinate
//! the outer code.
//!
//! The producer closes the channel after its last send so the consumer's
//! `while let Some(v) = rx.recv()` loop terminates cleanly — the same
//! semantics as `close(ch)` in Go.
//!
//! ```sh
//! cargo run --example scope_channel
//! ```