Skip to content

Instantly share code, notes, and snippets.

@tommythorn
Created May 10, 2022 06:02
Show Gist options
  • Save tommythorn/3f8e141ed6c6e528ba17f8284669c2d7 to your computer and use it in GitHub Desktop.
Save tommythorn/3f8e141ed6c6e528ba17f8284669c2d7 to your computer and use it in GitHub Desktop.
Failed attempt at Using Stakker
use stakker::*;
use std::time::{Duration, Instant};
struct Foo {
bar: Actor<Bar>,
}
impl Foo {
pub fn init(cx: CX![], bar: Actor<Bar>) -> Option<Self> {
call!([cx], run());
Some(Self { bar })
}
pub fn run(&mut self, _cx: CX![]) {
println!("foo");
call!([self.bar], run());
}
}
struct Bar {
foo_opt: Option<Actor<Foo>>,
}
impl Bar {
pub fn init(_cx: CX![]) -> Option<Self> {
Some(Self { foo_opt: None })
}
pub fn set_foo(&mut self, _cx: CX![], foo: Actor<Foo>) {
self.foo_opt = Some(foo);
}
pub fn run(&mut self, _cx: CX![]) {
println!("Bar");
let foo = self.foo_opt.as_ref().expect("Foo not setup");
call!([foo], run());
}
}
fn main() {
let mut stakker0 = Stakker::new(Instant::now());
let stakker = &mut stakker0;
let bar = actor!(stakker, Bar::init(), ret_nop!());
let foo = actor!(stakker, Foo::init(bar.clone()), ret_nop!());
call!([bar], set_foo(foo));// <--"expected struct `stakker::Actor`, found struct `ActorOwn`"
stakker.run(Instant::now(), false);
while stakker.not_shutdown() {
let maxdur = stakker.next_wait_max(Instant::now(), Duration::from_secs(60), false);
std::thread::sleep(maxdur);
stakker.run(Instant::now(), false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment