[][src]Struct greenie::fiber::Fiber

pub struct Fiber<T> { /* fields omitted */ }

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]

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]

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

impl<T> !UnwindSafe for Fiber<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.