Skip to content

"inverted control" mode through Proc::instance #772

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion hyperactor/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ pub trait Actor: Sized + Send + Debug + 'static {
}
}

/// An actor that does nothing. It is used to represent "client only" actors,
/// returned by [`Proc::instance`].
#[async_trait]
impl Actor for () {
type Params = ();

async fn new(params: Self::Params) -> Result<Self, anyhow::Error> {
Ok(params)
}
}

/// A Handler allows an actor to handle a specific message type.
#[async_trait]
pub trait Handler<M>: Actor {
Expand Down Expand Up @@ -356,6 +367,16 @@ pub enum Signal {
ChildStopped(Index),
}

impl fmt::Display for Signal {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Signal::DrainAndStop => write!(f, "DrainAndStop"),
Signal::Stop => write!(f, "Stop"),
Signal::ChildStopped(index) => write!(f, "ChildStopped({})", index),
}
}
}

/// The runtime status of an actor.
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Named)]
pub enum ActorStatus {
Expand Down Expand Up @@ -390,7 +411,7 @@ pub enum ActorStatus {

impl ActorStatus {
/// Tells whether the status is a terminal state.
fn is_terminal(&self) -> bool {
pub(crate) fn is_terminal(&self) -> bool {
matches!(self, Self::Stopped | Self::Failed(_))
}

Expand Down
Loading