apple / apple/swift-async-algorithms

No way to tell if `AsyncChannel` is closed

Open
#355 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
3.7k
Forks
226
Avg merge
10d 3h
Merged PRs (30d)
1

Description

When a channel is closed, `send()` simply will return instantly.

If you have an API that returns a channel for consumption, the producer has no way of knowing a channel was closed by the consumer. `send()` should really throw an error instead of just losing all back pressure instantly. That kind of defeats the purpose of a channel.

If any producer and consumer is allowed to call `finish()`, any producer and consumer must also be able to check if a channel was finished.

This has nothing to do with a `1:1` relationship as stated in https://github.com/apple/swift-async-algorithms/issues/304

Also for instance in [go](https://go.dev), writing to a closed channel is forbidden and will panic.

Contributor guide

Open the contributing guide

Research direction

Start with the AsyncChannel send() and finish() entry points, then read the issue 304 discussion linked in the report. Work out the intended behavior when a consumer closes the channel and when producers attempt to send afterward; done means the channel lifecycle semantics are agreed and implemented with corresponding tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.