You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asyncband.apache.org by "tisonkun (via GitHub)" <gi...@apache.org> on 2026/08/30 16:18:01 UTC
[I] design(watch): finalize value ownership and sender state APIs [asyncband]
tisonkun opened a new issue, #251:
URL: https://github.com/apache/asyncband/issues/251
## Goal
Finalize the public `watch` API before 0.7 by separating latest-state/version semantics from the value ownership policy.
## Potential changes
- Replace the public `Arc<T>` results from `Receiver::{borrow, borrow_and_update, changed}` with a borrowed core: `Ref<'_, T>` for value access and `changed() -> Result<(), RecvError>` for notification.
- Optionally add an owned convenience such as `recv() -> Result<T, RecvError> where T: Clone`; callers can choose `T = Arc<U>` when they need cheap shared snapshots.
- Add `Sender::send_replace(T) -> T` so the retained state can be updated while no receivers exist, while keeping the current `send` failure behavior unchanged.
- Consider symmetric `Sender::borrow` and `Sender::is_disconnected` inspection methods.
## Contracts to preserve
- The initial value and the current value at `subscribe` time are considered seen.
- Every successful publication creates a new version, even when values compare equal.
- Intermediate updates may coalesce independently for each receiver.
- Receiver clones inherit the source receiver's seen state and then advance independently.
- A final unseen value is observable before disconnection is reported.
- `changed` remains cancellation safe, and user wakers/destructors continue to run outside internal locks.
## Design note
The ownership choices have different costs: a borrowed `Ref` exposes the lock lifetime, returning `T` requires cloning, and returning `Arc<T>` fixes shared ownership and allocation in the public contract. This should be decided as one coherent API model rather than as a return-type-only substitution.
Follow-up to #215 and #233. Related discussion: #222.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For additional commands, e-mail: commits-help@asyncband.apache.org
Re: [I] design(watch): finalize value ownership and sender state APIs [asyncband]
Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on issue #251:
URL: https://github.com/apache/asyncband/issues/251#issuecomment-5469887727
[asyncband-watch-api-review.md](https://github.com/user-attachments/files/31617753/asyncband-watch-api-review.md)
Here is my chat with GPT in Chinese. I may disagree some GPT outputs so need not to follow what GPT says one by one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For additional commands, e-mail: commits-help@asyncband.apache.org
Re: [I] design(watch): finalize value ownership and sender state APIs [asyncband]
Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun closed issue #251: design(watch): finalize value ownership and sender state APIs
URL: https://github.com/apache/asyncband/issues/251
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For additional commands, e-mail: commits-help@asyncband.apache.org
Re: [I] design(watch): finalize value ownership and sender state APIs [asyncband]
Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on issue #251:
URL: https://github.com/apache/asyncband/issues/251#issuecomment-5476987534
@QwQBiG You may check your email inbox :D
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For additional commands, e-mail: commits-help@asyncband.apache.org
Re: [I] design(watch): finalize value ownership and sender state APIs [asyncband]
Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on issue #251:
URL: https://github.com/apache/asyncband/issues/251#issuecomment-5476377483
OK. I will consider this today.
> Since you mentioned that you could handle this when you have time, I’d like to leave the implementation to you rather than add a speculative patch or more review noise.
Actually, I mean to leave it to you altogether. But I'd prefer to include this API design decision in the upcoming 0.7 release and it may require some experience on API design, I can handle it myself now. However, I'd appreciate it if more contributors would consider what asyncband's APIs should look like, whether they are reasonable to deliver, and whether they have good ergonomics for downstream users.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For additional commands, e-mail: commits-help@asyncband.apache.org
Re: [I] design(watch): finalize value ownership and sender state APIs [asyncband]
Posted by "QwQBiG (via GitHub)" <gi...@apache.org>.
QwQBiG commented on issue #251:
URL: https://github.com/apache/asyncband/issues/251#issuecomment-5476673075
Got it—thanks for clarifying! I misunderstood “leave it to you” in exactly the opposite direction TwT
Given that this will shape the 0.7 public API, it makes sense for you to drive the implementation. I’ll keep following the design and review the final diff from a downstream user’s perspective. If I spot a concrete ergonomics issue or useful example, I’ll chime in.
Looking forward to learning from this one!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For additional commands, e-mail: commits-help@asyncband.apache.org
Re: [I] design(watch): finalize value ownership and sender state APIs [asyncband]
Posted by "QwQBiG (via GitHub)" <gi...@apache.org>.
QwQBiG commented on issue #251:
URL: https://github.com/apache/asyncband/issues/251#issuecomment-5470148238
Thanks for the design quiz! :P
GPT hallucinates, but so do I—maybe peer-reviewing each other under pressure will keep us both honest…
Give me 48 hours to dig into the existing contract and work through the ownership/liveness trade-offs before touching the code. I’ll follow up either way tomorrow. If I still don’t have a defensible proposal by then, I won’t force a half-baked solution—I'll let you know so you can take a look whenever you have bandwidth.
And…晚安~
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For additional commands, e-mail: commits-help@asyncband.apache.org
Re: [I] design(watch): finalize value ownership and sender state APIs [asyncband]
Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on issue #251:
URL: https://github.com/apache/asyncband/issues/251#issuecomment-5478897199
Decision range:
1. Sender
* Cloneable
* send(T) -> Result<(), SendError<T>>
* send_replace(T) -> T
2. Receiver
* Cloneable
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For additional commands, e-mail: commits-help@asyncband.apache.org
Re: [I] design(watch): finalize value ownership and sender state APIs [asyncband]
Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on issue #251:
URL: https://github.com/apache/asyncband/issues/251#issuecomment-5469853688
@QwQBiG Here are some rough ideas I instructed GPT to outline to polish the `watch` primitives.
I suppose some of them can be reasonable, while others may be LLM hallucinations.
You can take this input and see whether the contract of `watch` can be refined and improved (it's possible nothing needs to change).
I can handle this when I have time, but I think it's a fair design quiz, so I'd like to leave it to you first.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For additional commands, e-mail: commits-help@asyncband.apache.org
Re: [I] design(watch): finalize value ownership and sender state APIs [asyncband]
Posted by "QwQBiG (via GitHub)" <gi...@apache.org>.
QwQBiG commented on issue #251:
URL: https://github.com/apache/asyncband/issues/251#issuecomment-5476273189
Hi~ @tisonkun
After going through the issue and the current implementation once more, I agree with the issue’s central framing: this should be settled as one coherent ownership model, not as a few isolated return-type changes.
Among the options already laid out in the issue, my preference is the borrowed core—`Ref<'_, T>` for access, `changed() -> Result<(), RecvError>` for notification, together with `send_replace(T) -> T`. The current `Arc<T>` API from #233 is sound: it supports non-`Clone` values, returns owning snapshots, and does not leave callers holding the channel lock. Its trade-off is that shared ownership and an allocation per publication become part of the public contract. If Asyncband wants the more ownership-neutral primitive, the borrowed direction looks cleaner to me. If a full redesign is not worthwhile, however, I think keeping the current `Arc<T>` model unchanged would be better than adopting only part of the proposal.
My main implementation concern is that a borrowed design should separate the value lock from version and waiter state. A retained `Ref` would then block publication, but should not block endpoint lifecycle or waiter bookkeeping. The documentation would also need to clearly warn against holding a `Ref` across `.await`.
I would defer `recv()` and the optional sender inspection methods until their use cases and exact semantics are clearer. In particular, I checked `async-watch::recv()`: it calls `changed().await` and then `borrow().clone()`, so another publication between those operations means it does not guarantee an atomic same-version snapshot. I would not copy that convenience without first deciding whether this race is part of the intended contract.
Since you mentioned that you could handle this when you have time, I’d like to leave the implementation to you rather than add a speculative patch or more review noise. This is my current reading of the trade-offs, and I’ll stop here and learn from whichever final model you choose. Thanks again for the design quiz! :D
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For additional commands, e-mail: commits-help@asyncband.apache.org