Created
August 2, 2013 22:43
-
-
Save olsonjeffery/6144057 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this rust? Looks like you are still using emacs. Yay! We should get together and hack some weekend.