75 lines
931 B
Rust
75 lines
931 B
Rust
#[macro_use]
|
|
extern crate scribe;
|
|
|
|
extern crate apprentice;
|
|
|
|
|
|
use apprentice::*;
|
|
|
|
|
|
|
|
struct TestTask
|
|
{
|
|
count: u8
|
|
}
|
|
|
|
impl TestTask
|
|
{
|
|
pub fn new() -> TestTask
|
|
{
|
|
TestTask
|
|
{
|
|
count: 0
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Task for TestTask
|
|
{
|
|
fn get_name(&self) -> &str
|
|
{
|
|
"TestTask"
|
|
}
|
|
|
|
fn get_mortality(&self) -> Mortality
|
|
{
|
|
Mortality::Mortal
|
|
}
|
|
|
|
fn get_priority(&self) -> Priority
|
|
{
|
|
Priority::Normal
|
|
}
|
|
|
|
fn reset(&mut self)
|
|
{
|
|
self.count = 0;
|
|
}
|
|
|
|
fn process(&mut self, spawner: &mut Spawner) -> bool
|
|
{
|
|
self.count += 1;
|
|
println!("{}: {}", self.get_name(), self.count);
|
|
|
|
if self.count > 2
|
|
{
|
|
return true;
|
|
}
|
|
|
|
false
|
|
}
|
|
}
|
|
|
|
|
|
pub fn main()
|
|
{
|
|
let mut scheduler: Scheduler;
|
|
|
|
scheduler = Scheduler::new(None, Some(4));
|
|
scheduler.queue_task(TestTask::new());
|
|
loop
|
|
{
|
|
scheduler.process_tasks(true);
|
|
}
|
|
}
|