pub struct Runtime { /* private fields */ }Expand description
The main component of acril_rt - the runtime. It stores the running services
and handles their lifecycle and messages sent to them.
Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/ping.rs (line 94)
89async fn main() {
90 // make sure the runtime can spawn !Send tasks
91 let local_set = tokio::task::LocalSet::new();
92 let _guard = local_set.enter();
93
94 let runtime = acril_rt::Runtime::new();
95
96 local_set.run_until(async move {
97 #[cfg(debug_assertions)]
98 let printer = runtime.spawn(Printer::ToStdout).await;
99 #[cfg(not(debug_assertions))]
100 let printer = runtime.spawn(Printer::ToString(String::new())).await;
101 let pinger = runtime.spawn(Pinger { count: 0 }).await;
102
103 printer.send("Liftoff!".to_string()).await.unwrap();
104
105 for i in 0..10000 {
106 let pong = pinger.send(Ping).await.unwrap();
107
108 // i is 0-based and pong is 1-based because the pinger increments before returning
109 assert_eq!(pong.0, i + 1);
110
111 printer.send(format!("pong #{}", pong.0)).await.unwrap();
112 }
113
114 assert_eq!(pinger.send(GetOutput).await.unwrap(), 10000);
115 #[cfg(not(debug_assertions))]
116 // assert that the output is Ok(Some(non_empty_string))
117 assert!(!printer.send(GetOutput).await.unwrap().unwrap().is_empty());
118
119 printer.send("We're done!".to_string()).await.unwrap();
120 }).await;
121}pub fn new_in(arbiter: &ArbiterHandle) -> Self
Sourcepub async fn spawn<S: Service<Context = Context<S>> + Send + Sync + 'static>(
&self,
service: S,
) -> Addr<S>
pub async fn spawn<S: Service<Context = Context<S>> + Send + Sync + 'static>( &self, service: S, ) -> Addr<S>
Examples found in repository?
examples/ping.rs (line 98)
89async fn main() {
90 // make sure the runtime can spawn !Send tasks
91 let local_set = tokio::task::LocalSet::new();
92 let _guard = local_set.enter();
93
94 let runtime = acril_rt::Runtime::new();
95
96 local_set.run_until(async move {
97 #[cfg(debug_assertions)]
98 let printer = runtime.spawn(Printer::ToStdout).await;
99 #[cfg(not(debug_assertions))]
100 let printer = runtime.spawn(Printer::ToString(String::new())).await;
101 let pinger = runtime.spawn(Pinger { count: 0 }).await;
102
103 printer.send("Liftoff!".to_string()).await.unwrap();
104
105 for i in 0..10000 {
106 let pong = pinger.send(Ping).await.unwrap();
107
108 // i is 0-based and pong is 1-based because the pinger increments before returning
109 assert_eq!(pong.0, i + 1);
110
111 printer.send(format!("pong #{}", pong.0)).await.unwrap();
112 }
113
114 assert_eq!(pinger.send(GetOutput).await.unwrap(), 10000);
115 #[cfg(not(debug_assertions))]
116 // assert that the output is Ok(Some(non_empty_string))
117 assert!(!printer.send(GetOutput).await.unwrap().unwrap().is_empty());
118
119 printer.send("We're done!".to_string()).await.unwrap();
120 }).await;
121}Auto Trait Implementations§
impl Freeze for Runtime
impl RefUnwindSafe for Runtime
impl Send for Runtime
impl Sync for Runtime
impl Unpin for Runtime
impl UnwindSafe for Runtime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more