Skip to content

Commit b48988a

Browse files
mariusaefacebook-github-bot
authored andcommitted
"inverted control" mode through Proc::instance
Summary: X-link: #772 Adds Proc::instance() which returns an actor instance and its corresponding handler. This allows the user to create a regular actor without any message handlers. The returned `Instance` provides all the normal capabilities, including sending and receiving messages, being able to spawn and manage child actors, etc. This is the foundation for a kind of "script mode" actor. Reviewed By: shayne-fletcher Differential Revision: D79685752 fbshipit-source-id: ae9ed96cd6ba8cc49c4144b85004f850cc597472
1 parent 5f5735c commit b48988a

File tree

3 files changed

+202
-50
lines changed

3 files changed

+202
-50
lines changed

hyperactor/src/actor.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ pub trait Actor: Sized + Send + Debug + 'static {
135135
}
136136
}
137137

138+
/// An actor that does nothing. It is used to represent "client only" actors,
139+
/// returned by [`Proc::instance`].
140+
#[async_trait]
141+
impl Actor for () {
142+
type Params = ();
143+
144+
async fn new(params: Self::Params) -> Result<Self, anyhow::Error> {
145+
Ok(params)
146+
}
147+
}
148+
138149
/// A Handler allows an actor to handle a specific message type.
139150
#[async_trait]
140151
pub trait Handler<M>: Actor {
@@ -356,6 +367,16 @@ pub enum Signal {
356367
ChildStopped(Index),
357368
}
358369

370+
impl fmt::Display for Signal {
371+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
372+
match self {
373+
Signal::DrainAndStop => write!(f, "DrainAndStop"),
374+
Signal::Stop => write!(f, "Stop"),
375+
Signal::ChildStopped(index) => write!(f, "ChildStopped({})", index),
376+
}
377+
}
378+
}
379+
359380
/// The runtime status of an actor.
360381
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Named)]
361382
pub enum ActorStatus {
@@ -390,7 +411,7 @@ pub enum ActorStatus {
390411

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

0 commit comments

Comments
 (0)