Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
64
third-party/vendor/generator/examples/cd.rs
vendored
Normal file
64
third-party/vendor/generator/examples/cd.rs
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
use generator::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Action {
|
||||
Play(&'static str),
|
||||
Stop,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
enum State {
|
||||
Playing,
|
||||
Stopped,
|
||||
}
|
||||
|
||||
use crate::Action::*;
|
||||
use crate::State::*;
|
||||
|
||||
fn main() {
|
||||
let mut cd_player = Gn::new_scoped(|mut s| {
|
||||
let mut state = Stopped;
|
||||
loop {
|
||||
// println!("{:?}", *state);
|
||||
// in release mod without this there is bugs!!!!! (rustc 1.59.0 (9d1b2106e 2022-02-23))
|
||||
std::sync::atomic::compiler_fence(std::sync::atomic::Ordering::AcqRel);
|
||||
|
||||
match state {
|
||||
Stopped => match s.get_yield() {
|
||||
Some(Play(t)) => {
|
||||
println!("I'm playing {t}");
|
||||
state = Playing;
|
||||
}
|
||||
Some(Stop) => println!("I'm already stopped"),
|
||||
_ => unreachable!("some thing wrong"),
|
||||
},
|
||||
|
||||
Playing => match s.get_yield() {
|
||||
Some(Stop) => {
|
||||
println!("I'm stopped");
|
||||
state = Stopped;
|
||||
}
|
||||
Some(Play(_)) => println!("should first stop"),
|
||||
_ => unreachable!("some thing wrong"),
|
||||
},
|
||||
}
|
||||
|
||||
s.yield_with(state);
|
||||
}
|
||||
});
|
||||
|
||||
for _ in 0..1000 {
|
||||
let ret = cd_player.send(Play("hello world"));
|
||||
assert_eq!(ret, Playing);
|
||||
let ret = cd_player.send(Play("hello another day"));
|
||||
assert_eq!(ret, Playing);
|
||||
let ret = cd_player.send(Stop);
|
||||
assert_eq!(ret, Stopped);
|
||||
let ret = cd_player.send(Stop);
|
||||
assert_eq!(ret, Stopped);
|
||||
let ret = cd_player.send(Play("hello another day"));
|
||||
assert_eq!(ret, Playing);
|
||||
let ret = cd_player.send(Stop);
|
||||
assert_eq!(ret, Stopped);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue