[−][src]Struct greenie::fiber::Fiber
Fiber objects are lightweight microthreads which are cooperatively scheduled.
Only one can run at a given time and the Fiber::yield()
or yield_thread
functions must be used to switch execution from one fiber to another.
Methods
impl<T> Fiber<T>
[src]
pub fn new<F: FnOnce() -> T + Clone + 'static>(closure: F) -> Self
[src]
Create new fiber.
Example
use greenie::*; create_main( || { let some_variable = 42; let fiber = Fiber::new(move || { println!("{}",some_variable); return "Complete"; }); fiber.start(); println!("{}",fiber.join().unwrap()); });
pub fn new_capture<F: 'static, A: 'static + ApplyTo<F, Result = T> + Clone>(
closure: F,
args: A
) -> Self
[src]
closure: F,
args: A
) -> Self
Creates new fiber. Main difference from Fiber::new
is that you can
capture some variables from context much easier:
use greenie::*; create_main( || { let some_variable = 42; let fiber = Fiber::new_capture( |v,_| { println!("{}",v); return "Complete"; },(some_variable,())); fiber.start(); println!("{}",fiber.join().unwrap()); });
pub fn yield_(&self)
[src]
pub fn start(&self) -> Result<(), &'static str>
[src]
Starts or resumes the execution of this fiber.
pub fn join(self) -> Result<T, Box<dyn Any>> where
T: 'static,
[src]
T: 'static,
Waits for the associated fiber to finish.
pub fn is_alive(&self) -> bool
[src]
Returns true if the fiber hasn't ended yet, false if it has already ended.
pub fn suspend(&self)
[src]
Pause fiber execution.
Auto Trait Implementations
impl<T> !RefUnwindSafe for Fiber<T>
impl<T> !Send for Fiber<T>
impl<T> !Sync for Fiber<T>
impl<T> Unpin for Fiber<T> where
T: Unpin,
T: Unpin,
impl<T> !UnwindSafe for Fiber<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,