Discuss shared broadcast receives without a Clone bound
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 30/100
- issue の種類
- 機能追加
- 明瞭さ
- 説明が足りない
- 活発さ
- 活発
- 技術スタック
- rust
調査の方向性
Start by reading asyncband/src/broadcast/mpmc/common.rs, especially the shared backlog and take_msg, then compare the bounded and unbounded receiver APIs. Resolve whether shared receives should be added and how they interact with existing owning receives; done requires an accepted API direction plus validation of non-Clone fan-out, cancellation, capacity release, and existing receive behavior.
索引モデルが issue の本文から書いたものです。
説明
Problem
Both bounded and unbounded broadcast currently require T: Clone at construction and return T from recv / try_recv. Multiple subscribers need access to each published value, but requiring an owned T for every receive is an API choice rather than a requirement of the backing storage.
The shared backlog already stores VecDeque<Arc<T>>. Receiving obtains an Arc<T>, and take_msg converts it to T: it clones the payload when needed and attempts to move it out when the message is reclaimed. Payload cloning and destruction happen outside channel locks.
Callers can already use T = Arc<State> without requiring State: Clone, but the internal representation then becomes Arc<Arc<State>>. Exposing shared ownership of the existing message could avoid the additional Arc layer.
This issue is an open design discussion. The API below is a candidate, not an accepted implementation specification.
Candidate: add shared receives and preserve owning receives
Relax the T: Clone bound on both constructors. On both receiver types, add methods available for any T:
pub async fn recv_shared(&mut self) -> Result<Arc<T>, RecvError>;
pub fn try_recv_shared(&mut self) -> Result<Arc<T>, TryRecvError>;
Keep the existing recv and try_recv methods returning T, with T: Clone required only for those methods.
The two receive forms would consume from the same subscription cursor. Choosing a return representation would neither create a new subscription nor deliver the same message twice to one subscription. Bounded and unbounded channels should expose consistent APIs.
Compatibility
- Relaxing constructor bounds preserves existing calls and permits non-Clone payloads.
- Adding shared receive methods preserves the existing owning API. As with any new Rust inherent method, a name collision with a downstream extension trait is a possible compatibility edge case; see the Cargo guidance.
- Changing the existing
recv/try_recvreturn type toArc<T>, or renaming the old methods to give their names to shared receives, breaks existing callers. - Preserve the existing move-out optimization. Implementing owning receives as an unconditional clone of a shared receive would lose the current guarantee that a channel with a single receiver does not clone its payload.
- At this discussion's starting point, unbounded broadcast is present in
v0.7.2, while bounded broadcast was added for the next release in #253. Changing only the unreleased bounded API would not break a released API, but would leave the two channel variants inconsistent.
Semantics and tradeoffs
Shared receives must preserve message ordering, cancellation safety, disconnection behavior, and capacity accounting. Reclaimed bounded capacity must be released before running payload clone or drop callbacks.
Once every subscription has consumed a message or been dropped, the message can leave the backlog and release its queue capacity. An Arc<T> retained by a caller can nevertheless keep the payload allocation alive. Bounded capacity would limit retained backlog messages, not all memory held by completed receives.
A shared result gives subscribers ownership of the same allocation. An owning result gives them a T according to that type's Clone semantics, which need not be a deep copy. These are useful distinct contracts, but exposing both adds API surface and commits the shared path to Arc-based ownership.
Keeping the current API and asking callers to choose T = Arc<State> remains an alternative. It keeps the public API smaller at the cost of the extra Arc layer. Replacing owning receives with shared receives gives one default ownership model, but requires an explicit breaking-change decision.
Questions to resolve
- Is avoiding payload Clone requirements and nested Arc storage worth adding a permanent shared receive API?
- Are
recv_shared/try_recv_sharedthe right names and the right place to express the ownership choice? - Should we adopt the additive design, retain the current caller-selected Arc approach, or consider a shared-by-default API in a future incompatible release?
If the additive design is selected, validation should cover non-Clone payload fan-out, mixed shared and owning receives on one cursor, cancellation, bounded capacity release while returned Arcs remain alive, and preservation of existing owning-receive behavior.
Related: #311 narrows Watch's constructor bound without changing its return-value ownership model. Part of the channel-family discussion in #206.
- 主要言語
- Rust
- スター
- 283
- フォーク
- 49
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 39
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/asyncband のほかの issue
-
Tracking Issue to Release 0.7.4対応中かも @QwQBiG が 4 日前に担当しました。 オープン
apache/asyncband#369 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Investigate unsound mapped RwLock write guard downgrading対応中かも @orthur2 が 7 日前に担当しました。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
apache/asyncband#362 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
apache/asyncband#360 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement good first issue help wanted
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
apache/asyncband#324 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement help wanted
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
apache/asyncband#298 · コメント 7 件 ·
メンテナーはふだん 1 日以内に返信
apache/asyncband の issue をすべて見る
似ている issue
-
area:gc-repack-output bug factory:dogfood factory:triaged priority:p3 type:bug type:ux
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
gitbutlerapp/grit#1161 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
feature
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
-
priority: low
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
storytold/photocraft#7520 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信