-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PostStart actor after PocketIcProxy actor to output info messages.
- Loading branch information
1 parent
1179330
commit 95f32db
Showing
4 changed files
with
116 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use crate::actors::post_start::signals::{PocketIcProxyReadySignal, PocketIcProxyReadySubscribe}; | ||
use crate::actors::pocketic_proxy::PocketIcProxy; | ||
use actix::{Actor, Addr, AsyncContext, Context, Handler}; | ||
use slog::{info, Logger}; | ||
|
||
pub mod signals { | ||
use actix::prelude::*; | ||
|
||
#[derive(Message)] | ||
#[rtype(result = "()")] | ||
pub struct PocketIcProxyReadySignal; | ||
|
||
#[derive(Message)] | ||
#[rtype(result = "()")] | ||
pub struct PocketIcProxyReadySubscribe(pub Recipient<PocketIcProxyReadySignal>); | ||
} | ||
|
||
pub struct Config { | ||
pub logger: Logger, | ||
pub background: bool, | ||
pub pocketic_proxy: Option<Addr<PocketIcProxy>>, | ||
} | ||
|
||
pub struct PostStart { | ||
config: Config, | ||
} | ||
|
||
impl PostStart { | ||
pub fn new(config: Config) -> Self { | ||
Self { config } | ||
} | ||
} | ||
|
||
impl Actor for PostStart { | ||
type Context = Context<Self>; | ||
|
||
fn started(&mut self, ctx: &mut Self::Context) { | ||
// Register the PostStart recipent to PocketIcProxy. | ||
if let Some(pocketic_proxy) = &self.config.pocketic_proxy { | ||
pocketic_proxy.do_send(PocketIcProxyReadySubscribe(ctx.address().recipient())); | ||
} | ||
} | ||
} | ||
|
||
impl Handler<PocketIcProxyReadySignal> for PostStart { | ||
type Result = (); | ||
|
||
fn handle(&mut self, _msg: PocketIcProxyReadySignal, _ctx: &mut Self::Context) -> Self::Result { | ||
let logger = &self.config.logger; | ||
if self.config.background { | ||
info!(logger, "The dfx server is running in the background.") | ||
} else { | ||
info!(logger, "The dfx server is running.\nYou can start a new terminal to continue developing, or quit with 'Ctrl-C'."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters