Skip to content

Replace custom state management with conducer crate#1043

Closed
kixelated wants to merge 5 commits intomainfrom
claude/migrate-conducer-crate-x7bwH
Closed

Replace custom state management with conducer crate#1043
kixelated wants to merge 5 commits intomainfrom
claude/migrate-conducer-crate-x7bwH

Conversation

@kixelated
Copy link
Collaborator

This PR replaces the custom state.rs and waiter.rs modules with the external conducer crate, which provides equivalent producer-consumer state management functionality.

Summary

Removed ~600 lines of custom state management code and replaced it with the conducer crate dependency. This simplifies the codebase by leveraging a dedicated, well-tested library for producer-consumer patterns.

Key Changes

  • Removed modules: state.rs and waiter.rs containing custom Producer, Consumer, Weak, and Waiter implementations
  • Added dependency: conducer = "0.1" in Cargo.toml
  • Updated imports: All modules now import Producer, Consumer, Weak, and Waiter from conducer crate
  • API adaptations:
    • Replaced state.abort(err) calls with state.close(conducer::Error::Closed)
    • Replaced waiter_fn() with wait() from conducer
    • Updated error handling to convert between conducer::Error and local Error type via new From implementation
    • Wrapped unused() calls with Ok() to handle result type differences
    • Updated closed() return values to convert conducer::Error to local Error
  • Affected modules: track.rs, broadcast.rs, frame.rs, group.rs, and error.rs

Implementation Details

  • Added From<conducer::Error> implementation in error.rs to handle conversion between the two error types
  • The conducer crate provides the same producer-consumer semantics with waiter registration and notification
  • All functional behavior is preserved; this is purely a refactoring to use an external dependency

https://claude.ai/code/session_01MdwQB5R1RF7GY3DVqwdxS2

claude added 5 commits March 3, 2026 19:51
Replace the internal Producer/Consumer/Weak state machinery and waiter
system with the conducer crate, which provides the same API.

Key changes:
- Add conducer 0.1 dependency
- Remove model/state.rs and model/waiter.rs (~616 lines)
- Add From<conducer::Error> for crate::Error conversion
- Replace waiter_fn -> conducer::wait
- Replace state.abort(err) -> state.close(conducer::Error::Closed)
- Simplify TrackConsumer::closed() since conducer only returns
  Closed/Dropped (both are normal closures)

https://claude.ai/code/session_01MdwQB5R1RF7GY3DVqwdxS2
Update to conducer 0.1.1 which removes conducer::Error in favor of
Option returns. Each internal State type now has an `abort: Option<Error>`
field that stores the error when explicitly aborted.

Key changes:
- Remove From<conducer::Error> impl (conducer::Error no longer exists)
- Add `abort: Option<Error>` to FrameState, GroupState, track::State,
  broadcast::State
- Add `err()` helper on all Producer/Consumer wrappers that borrows
  state to check abort, falling back to Error::Dropped
- Add `Weak<State>` to all Consumer types so they can read the abort
  error after the channel closes
- Convert all modify()/produce()/poll() None returns to the stored
  abort error via ok_or_else(|| self.err())
- Set state.abort before calling state.close() in all abort methods

https://claude.ai/code/session_01MdwQB5R1RF7GY3DVqwdxS2
Replaces `self.state.modify().ok_or_else(|| self.err())?` with
`self.modify()?` across FrameProducer, GroupProducer, TrackProducer,
BroadcastProducer, and BroadcastDynamic.

https://claude.ai/code/session_01MdwQB5R1RF7GY3DVqwdxS2
access() returns ProducerAccess::Mut when open or ProducerAccess::Ref
when closed, reading the abort error in a single lock acquisition
instead of locking once for modify() and again for borrow() on failure.

https://claude.ai/code/session_01MdwQB5R1RF7GY3DVqwdxS2
…ures

Instead of storing a Weak<State> on each consumer to read the abort
error after channel close, the poll_* functions now return Result so
the error propagates naturally through the poll closure. This eliminates
the need for a separate err() call and the extra Weak reference.

Pattern: .await.ok_or(Error::Dropped)?? — outer ? unwraps the Option
(None = dropped without abort), inner ? unwraps the Result (Err = aborted).

https://claude.ai/code/session_01MdwQB5R1RF7GY3DVqwdxS2
@kixelated kixelated closed this Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants