Struct cosworth::prelude::ActixSystem
source · pub struct ActixSystem { /* private fields */ }
Expand description
System is an actor which manages runtime.
Before starting any actix’s actors, System
actor has to be created and
started with System::run()
call. This method creates new Arbiter
in
current thread and starts System
actor.
Examples
extern crate actix;
use actix::prelude::*;
use std::time::Duration;
struct Timer {
dur: Duration,
}
impl Actor for Timer {
type Context = Context<Self>;
// stop system after `self.dur` seconds
fn started(&mut self, ctx: &mut Context<Self>) {
ctx.run_later(self.dur, |act, ctx| {
// Stop current running system.
System::current().stop();
});
}
}
fn main() {
// initialize system and run it.
// This function blocks current thread
let code = System::run(|| {
// Start `Timer` actor
Timer {
dur: Duration::new(0, 1),
}.start();
});
std::process::exit(code);
}
Implementations§
source§impl System
impl System
sourcepub fn builder() -> Builder
pub fn builder() -> Builder
Build a new system with a customized tokio runtime.
This allows to customize the runtime. See struct level docs on
Builder
for more information.
sourcepub fn new<T>(name: T) -> SystemRunnerwhere
T: Into<String>,
pub fn new<T>(name: T) -> SystemRunnerwhere
T: Into<String>,
Create new system.
This method panics if it can not create tokio runtime
sourcepub fn with_current<F, R>(f: F) -> Rwhere
F: FnOnce(&System) -> R,
pub fn with_current<F, R>(f: F) -> Rwhere
F: FnOnce(&System) -> R,
Execute function with system reference.
sourcepub fn stop_with_code(&self, code: i32)
pub fn stop_with_code(&self, code: i32)
Stop the system with a particular exit code.
sourcepub fn registry(&self) -> &SystemRegistry
pub fn registry(&self) -> &SystemRegistry
Get current system registry.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for System
impl Send for System
impl Sync for System
impl Unpin for System
impl !UnwindSafe for System
Blanket Implementations§
source§impl<T> IntoSql for T
impl<T> IntoSql for T
source§fn into_sql<T>(self) -> Self::Expressionwhere
Self: AsExpression<T> + Sized,
fn into_sql<T>(self) -> Self::Expressionwhere
Self: AsExpression<T> + Sized,
Convert
self
to an expression for Diesel’s query builder. Read moresource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
Convert
&self
to an expression for Diesel’s query builder. Read more