Skip to content

Instantly share code, notes, and snippets.

@olsonjeffery
Created August 2, 2013 22:43
Show Gist options
  • Save olsonjeffery/6144057 to your computer and use it in GitHub Desktop.
Save olsonjeffery/6144057 to your computer and use it in GitHub Desktop.
pub fn connect(addr: IpAddr) -> Future<Option<TcpStreamAsync>> {
unsafe {
let (ret_future, ret_promise) = pair();
rtdebug!("borrowing io to connect");
let io = Local::unsafe_borrow::<IoFactoryObject>();
rtdebug!("about to connect");
let p_cell = Cell::new(ret_promise);
(*io).tcp_connect_async(addr,
|connect_result| {
let ret_promise = p_cell.take();
ret_promise.fulfill(connect_result);
}
);
let f_cell = Cell::new(ret_future);
future::from_fn(|| {
let ret_future = f_cell.take();
let r = ret_future.unwrap();
match r {
Ok(s) => Some(TcpStreamAsync::new(s)),
Err(e) => {
rtdebug!("failed to async connect: %?", e);
io_error::cond.raise(e);
None
}
}
})
}
}
@cbilson
Copy link

cbilson commented Aug 3, 2013

Is this rust? Looks like you are still using emacs. Yay! We should get together and hack some weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment