Struct flowync::Flower[][src]

pub struct Flower<SOME, OK> where
    SOME: Clone + Send + Sync + 'static,
    OK: Clone + Send + Sync + 'static, 
{ /* fields omitted */ }
Expand description

Flow loosely and gracefully.

Where:

SOME: type of Some value (Option<‘SOME’>)

OK: type of Ok value (Result<‘OK’, String>, and Err value always return String)

Quick Example:

use flowync::Flower;

fn main() {
    let flower = Flower::<i32, String>::new(1);
    std::thread::spawn({
        let handle = flower.handle();
        move || {
            // Start flowing to initialize.
            handle.start_flowing();
            for i in 0..10 {
                // Send current value through channel, will block the spawned thread
                // until the option value successfully being polled in the main thread.
                handle.send_current(i);
                // // Return error if the job is failure, for example:
                // if i >= 3 {
                //    return handle.err("Err".to_string());
                // }
            }
            // And return ok if the job successfully completed.
            return handle.ok("Ok".to_string());
        }
    });

    let mut exit = false;

    loop {
        // This fn will deactivate itself if the result contains a value.
        // Note: this fn is non-blocking (won't block the current thread).
        flower.try_recv(
            |option| {
                if let Some(value) = option {
                    println!("{}", value);
                }
            },
            |result| {
                match result {
                    Ok(value) => {
                        println!("{}", value);
                    }
                    Err(e) => {
                        println!("{}", e);
                    }
                }
                exit = true;
            },
        );

        if exit {
            break;
        }
    }
}

Implementations

Get ID of the flower.

Get handle of the flower.

Check if the flower is flowing

Cancel current flower handle.

will do noting if not explicitly configured.

Try receive the contained values of the flower

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.