diff --git a/examples/sample_tasks.rs b/examples/sample_tasks.rs index e0cd723..0d553d6 100644 --- a/examples/sample_tasks.rs +++ b/examples/sample_tasks.rs @@ -1,18 +1,74 @@ -extern crate apprentice; +#[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(Task::new("Test")); - scheduler.process_tasks(true); - scheduler.process_tasks(true); - //scheduler.process_tasks(true); + scheduler.queue_task(TestTask::new()); + loop + { + scheduler.process_tasks(true); + } }