{"action":"closed","issue":{"url":"https://api.github.com/repos/dwrensha/gjio/issues/7","repository_url":"https://api.github.com/repos/dwrensha/gjio","labels_url":"https://api.github.com/repos/dwrensha/gjio/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/dwrensha/gjio/issues/7/comments","events_url":"https://api.github.com/repos/dwrensha/gjio/issues/7/events","html_url":"https://github.com/dwrensha/gjio/issues/7","id":177981962,"number":7,"title":"Cannot use gjio timer in capnp-gj event loop","user":{"login":"simkha","id":22384,"avatar_url":"https://avatars.githubusercontent.com/u/22384?v=3","gravatar_id":"","url":"https://api.github.com/users/simkha","html_url":"https://github.com/simkha","followers_url":"https://api.github.com/users/simkha/followers","following_url":"https://api.github.com/users/simkha/following{/other_user}","gists_url":"https://api.github.com/users/simkha/gists{/gist_id}","starred_url":"https://api.github.com/users/simkha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simkha/subscriptions","organizations_url":"https://api.github.com/users/simkha/orgs","repos_url":"https://api.github.com/users/simkha/repos","events_url":"https://api.github.com/users/simkha/events{/privacy}","received_events_url":"https://api.github.com/users/simkha/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-20T07:07:48Z","updated_at":"2016-09-20T13:05:52Z","closed_at":"2016-09-20T13:05:52Z","body":"The following code won't compile. I've also setup a repo that you can clone to see this problem: https://github.com/simkha/async-io-timer-trouble.\r\n\r\n```rust\r\nextern crate gj;\r\nextern crate gjio;\r\nextern crate capnp;\r\nextern crate capnp_gj;\r\n\r\n// client periodically (3s) sends a random word request to the server\r\n// server prints request to stdout\r\n\r\nfn main() {\r\n    let _ : Vec<String> = ::std::env::args().collect();\r\n    \r\n    async_io_test::main();\r\n}\r\n\r\npub mod proto {\r\n    include!(concat!(env!(\"OUT_DIR\"), \"/proto_capnp.rs\"));\r\n}\r\n\r\n\r\npub mod async_io_test {\r\n    \r\n    use std::io;\r\n    use std::time::Duration;\r\n    use capnp;\r\n    use capnp::message;\r\n    use gj;\r\n    use gj::{Promise};\r\n    // use gjio;\r\n    use capnp_gj::serialize;\r\n    use capnp_gj::serialize::{OwnedSegments};\r\n    use gjio;\r\n    use gjio::{SocketStream, Timer};\r\n    use proto::request;\r\n    use proto::response;\r\n\r\n    pub fn main() {\r\n        gj::EventLoop::top_level(move |wait_scope| -> Result<(), io::Error> {\r\n            let mut event_port = try!(gjio::EventPort::new());\r\n            let network = event_port.get_network();\r\n            let (stream0, stream1) = try!(network.new_socket_pair());\r\n            \r\n            let (read, write) = (server_loop(stream1), client_loop(stream0, event_port.get_timer()));\r\n\r\n            Promise::all(vec![write, read].into_iter()).wait(wait_scope, &mut event_port).unwrap();\r\n            Ok(())\r\n        }).unwrap();\r\n    }\r\n\r\n    fn client_loop(stream: SocketStream, timer: Timer) -> Promise<(), capnp::Error> {\r\n        let message = prepare_request_message();\r\n\r\n        // write_message.then(process_message)\r\n        serialize::write_message(stream, message)//.map(|_| Ok(()))\r\n            .then(|(stream, _): (SocketStream, _)| {\r\n                // cannot use timer.after_delay because it expects \r\n                // the closure to return Promise<_, std::io::Error>,\r\n                // but we have Promise<_, capnp::Error>\r\n\r\n                timer.after_delay(Duration::from_millis(3000)).then(|()| {\r\n                    client_loop(stream, timer)\r\n                })\r\n            })\r\n    }\r\n\r\n    fn server_loop(stream: SocketStream) -> Promise<(), capnp::Error> {\r\n        // read_message.then(serve_response)\r\n\r\n        let print_message = |(stream, message_reader): (SocketStream, message::Reader<OwnedSegments>)| {\r\n            let response = message_reader.get_root::<response::Reader>().unwrap();\r\n            print_request_message(response);\r\n            // gj::Promise::ok(())\r\n\r\n            server_loop(stream)\r\n        };\r\n\r\n        serialize::read_message(stream, capnp::message::ReaderOptions::new())\r\n            .then(print_message)\r\n    }\r\n\r\n    fn prepare_request_message() -> message::Builder<message::HeapAllocator> {\r\n        let mut message = message::Builder::new_default();\r\n        {\r\n            let mut request = message.init_root::<request::Builder>();\r\n            request.set_word(\"hello\");\r\n        }\r\n\r\n        message\r\n    }\r\n\r\n    fn print_request_message(response: response::Reader) {\r\n        println!(\"server: got request: {:?}\", response.get_word());\r\n\r\n        ()\r\n    }\r\n\r\n}\r\n```"}}
{"actor":{"display_login":"simkha"}}