Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniform AsyncRuntime channel interfaces #1198

Closed
Tracked by #1013
SteveLauC opened this issue Jul 24, 2024 · 2 comments · Fixed by #1200
Closed
Tracked by #1013

Uniform AsyncRuntime channel interfaces #1198

SteveLauC opened this issue Jul 24, 2024 · 2 comments · Fixed by #1200
Assignees

Comments

@SteveLauC
Copy link
Collaborator

Trait AsyncRuntime exposes various associated channel types:

  • Oneshot
  • MPSC
  • Watch

Currently, both MPSC and Watch are exposed through traits:

https://github.com/datafuselabs/openraft/blob/ec284cb4813019d8b3a43a8cd74f3e1aa39eb882/openraft/src/type_config/async_runtime/mod.rs#L120-L122

Oneshot is different, it is scattered in the trait:

pub trait AsyncRuntime: Debug + Default + PartialEq + Eq + OptionalSend + OptionalSync + 'static {
    // Other fields are omitted

    type OneshotSender<T: OptionalSend>: OneshotSender<T> + OptionalSend + OptionalSync + Sized;
    type OneshotReceiverError: std::error::Error + OptionalSend;
    type OneshotReceiver<T: OptionalSend>: OptionalSend
        + OptionalSync
        + Future<Output = Result<T, Self::OneshotReceiverError>>
        + Unpin;
    fn oneshot<T>() -> (Self::OneshotSender<T>, Self::OneshotReceiver<T>)
    where T: OptionalSend;
}

To provide a consistent interface, I kinda think we should expose Oneshot in the way used by MPSC and Watch, i.e., something like:

pub trait Oneshot {
    type Sender<T: OptionalSend>: OneshotSender<T>;
    type Receiver<T: OptionalSend>: OptionalSend
        + OptionalSync
        + Future<Output = Result<T, Self::ReceiverError>>
        + Unpin;
    type ReceiverError: std::error::Error + OptionalSend;

    fn channel<T>() -> (Self::Sender<T>, Self::Receiver<T>)
    where T: OptionalSend;
}

pub trait AsyncRuntime: Debug + Default + PartialEq + Eq + OptionalSend + OptionalSync + 'static {
    // Other fields are omitted

    type MpscUnbounded: MpscUnbounded; 
    type Watch: Watch; 
    type Oneshot: Oneshot;
}
Copy link

👋 Thanks for opening this issue!

Get help or engage by:

  • /help : to print help messages.
  • /assignme : to assign this issue to you.

@SteveLauC SteveLauC changed the title Uniform the AsyncRuntime channel interfaces Uniform AsyncRuntime channel interfaces Jul 24, 2024
@SteveLauC
Copy link
Collaborator Author

/assignme

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 a pull request may close this issue.

1 participant