Skip to content

Instantly share code, notes, and snippets.

@apoelstra
Created July 9, 2014 18:14
Show Gist options
  • Save apoelstra/abeb129752f3f4fe16d2 to your computer and use it in GitHub Desktop.
Save apoelstra/abeb129752f3f4fe16d2 to your computer and use it in GitHub Desktop.
/// The "receiver set" of the select interface. This structure is used to manage
/// a set of receivers which are being selected over. The `Select` will act as a
/// receiver of type `U`. `'sel` is the lifetime of the stack frame of callbacks
/// which are passed to `Select::add`.
pub struct Select<'sel, U>;
/// A handle which is used to receive directly from a `Receiver` owned by a `Select`
pub struct RecvHandle<T>(uint);
impl<T:Send> RecvHandle<T> {
/// Receive data from the underlying `Receiver`. Pass in the
/// `Select` that this handle is attached to. It will fail!
/// if the handle did not originate with the passed-in `Select`.
pub fn recv_from<'sel, U>(&self, sel: &Select<'sel, U>) -> T {
...
}
}
impl<'sel, U> Select<'sel, U> {
/// Creates a new selection structure. This set is initially empty and
/// `wait` will fail!() if called.
pub fn new() -> Select<'sel, U> {
...
}
/// Installs a `Receiver` into a `Select`. Returns a handle which
/// can be used to receive directly from the original Receiver.
pub fn add<'a, T: Send>(&'a mut self, rx: Receiver<T>, callback: |T|: 'a -> U) -> RecvHandle<T> {
...
}
/// Waits for an event on this receiver set. When an event occurs,
/// receive from the appropriate Receiver, call its callback to
/// coerce the result to a `U`, and return this.
pub fn recv(&self) -> U {
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment