1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
//! Types related to futures and asynchrony.

mod error;
mod future_mem_map;
mod rw_vec;
mod mem_map;

use std;
use futures::future;
pub use self::error::{Error, Result};
// pub use self::rw_vec::{RwVec, Guard, FutureGuard, RwGuard, FutureRwGuard};
pub use self::rw_vec::{RwVec, ReadGuard, WriteGuard, FutureRwGuard, FutureReader, FutureWriter};
pub use self::mem_map::MemMap;
pub use self::future_mem_map::FutureMemMap;

pub type FutureResult<T> = future::FutureResult<T, self::Error>;


// * TODO: Implement this:
//
// pub struct EventListTrigger {
//     wait_events: EventList,
//     completion_event: UserEvent,
//     callback_is_set: bool,
// }

// pub struct EventTrigger {
//     wait_event: Event,
//     completion_event: UserEvent,
//     callback_is_set: bool,
// }

// impl EventTrigger {
//     pub fn new(wait_event: Event, completion_event: UserEvent) -> EventTrigger {
//         EventTrigger {
//             wait_event: wait_event,
//             completion_event: completion_event ,
//             callback_is_set: false,
//         }
//     }
// }



/// Creates a new "leaf future" which will resolve with the given result.
///
/// The returned future represents a computation which is finshed immediately.
/// This can be useful with the `finished` and `failed` base future types to
/// convert an immediate value to a future to interoperate elsewhere.
///
/// # Examples
///
/// ```
/// use ocl::async::result;
///
/// let future_of_1 = result::<u32>(Ok(1));
/// let future_of_err_2 = result::<u32>(Err("2".into()));
/// ```
///
//
// Shamelessly stolen from `https://github.com/alexcrichton/futures-rs`.
//
pub fn result<T>(r: std::result::Result<T, self::Error>) -> self::FutureResult<T> {
    future::result(r)
}

/// Creates a "leaf future" from an immediate value of a finished and
/// successful computation.
///
/// The returned future is similar to `done` where it will immediately run a
/// scheduled callback with the provided value.
///
/// # Examples
///
/// ```
/// use ocl::async::ok;
///
/// let future_of_1 = ok::<u32>(1);
/// ```
//
// Shamelessly stolen from `https://github.com/alexcrichton/futures-rs`.
//
pub fn ok<T>(t: T) -> self::FutureResult<T> {
    result(Ok(t))
}

/// Creates a "leaf future" from an immediate value of a failed computation.
///
/// The returned future is similar to `done` where it will immediately run a
/// scheduled callback with the provided value.
///
/// # Examples
///
/// ```
/// use ocl::async::err;
///
/// let future_of_err_1 = err::<u32>("1".into());
/// ```
//
// Shamelessly stolen from `https://github.com/alexcrichton/futures-rs`.
//
pub fn err<T>(e: self::Error) -> self::FutureResult<T> {
    result(Err(e))
}