You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most examples in this package lean on `@async.with_task_group` and `@io.pipe()` because they expose canonical `Reader` and `Writer` handles. The pattern scales to more complex topologies where multiple producers and consumers collaborate.
562
-
563
-
```moonbit
564
-
///|
565
-
async test "fan-out and fan-in" {
566
-
@async.with_task_group(fn(root) {
567
-
// Upstream producer pushes a header followed by the payload.
568
-
let (intermediate_reader, intermediate_writer) = @io.pipe()
569
-
root.spawn_bg(fn() {
570
-
defer intermediate_writer.close()
571
-
intermediate_writer.write(b"HDR")
572
-
@async.sleep(10)
573
-
intermediate_writer.write(b"PAYLOAD")
574
-
})
575
-
defer intermediate_reader.close()
576
-
577
-
// A downstream consumer receives the header via its own pipe.
// The original buffered reader still holds the payload.
590
-
@async.sleep(30)
591
-
let body = intermediate_reader.read_all().text()
592
-
inspect(body, content="PAYLOAD")
593
-
})
594
-
}
595
-
```
596
-
597
-
This example underscores how buffering plus task groups let you route data between multiple coroutines without copying or losing track of backpressure.
598
-
599
559
## Flow Control & Buffering Strategies
600
560
601
561
Efficient asynchronous I/O is mostly about balancing throughput and memory usage. Some guiding principles:
0 commit comments