{"action":"created","issue":{"url":"https://api.github.com/repos/carllerche/mio/issues/223","labels_url":"https://api.github.com/repos/carllerche/mio/issues/223/labels{/name}","comments_url":"https://api.github.com/repos/carllerche/mio/issues/223/comments","events_url":"https://api.github.com/repos/carllerche/mio/issues/223/events","html_url":"https://github.com/carllerche/mio/issues/223","id":98466684,"number":223,"title":"Composable event loop handlers","user":{"login":"tailhook","id":321799,"avatar_url":"https://avatars.githubusercontent.com/u/321799?v=3","gravatar_id":"","url":"https://api.github.com/users/tailhook","html_url":"https://github.com/tailhook","followers_url":"https://api.github.com/users/tailhook/followers","following_url":"https://api.github.com/users/tailhook/following{/other_user}","gists_url":"https://api.github.com/users/tailhook/gists{/gist_id}","starred_url":"https://api.github.com/users/tailhook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tailhook/subscriptions","organizations_url":"https://api.github.com/users/tailhook/orgs","repos_url":"https://api.github.com/users/tailhook/repos","events_url":"https://api.github.com/users/tailhook/events{/privacy}","received_events_url":"https://api.github.com/users/tailhook/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-31T20:35:54Z","updated_at":"2015-07-31T22:34:18Z","closed_at":null,"body":"Hi,\r\n\r\nThis issue is to start some discussion on how to build composable libraries with mio.\r\n\r\nBy being \"composable\" I mean the following. I have a library that implements protocol A and a library that implements a protocol B, and I can put both libraries on the same loop without writing tons of boilerplate code.\r\n\r\nAFAIU, it's a job of another library on top of mio, not mio itself. Have anybody seen such library? Do you know how to actually implement one? Thoughts?"},"comment":{"url":"https://api.github.com/repos/carllerche/mio/issues/comments/126828324","html_url":"https://github.com/carllerche/mio/issues/223#issuecomment-126828324","issue_url":"https://api.github.com/repos/carllerche/mio/issues/223","id":126828324,"user":{"login":"tailhook","id":321799,"avatar_url":"https://avatars.githubusercontent.com/u/321799?v=3","gravatar_id":"","url":"https://api.github.com/users/tailhook","html_url":"https://github.com/tailhook","followers_url":"https://api.github.com/users/tailhook/followers","following_url":"https://api.github.com/users/tailhook/following{/other_user}","gists_url":"https://api.github.com/users/tailhook/gists{/gist_id}","starred_url":"https://api.github.com/users/tailhook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tailhook/subscriptions","organizations_url":"https://api.github.com/users/tailhook/orgs","repos_url":"https://api.github.com/users/tailhook/repos","events_url":"https://api.github.com/users/tailhook/events{/privacy}","received_events_url":"https://api.github.com/users/tailhook/received_events","type":"User","site_admin":false},"created_at":"2015-07-31T22:34:18Z","updated_at":"2015-07-31T22:34:18Z","body":"Well, I didn't look at the question from this point of view :)\r\n\r\n> The main issue w/ sharing an EventLoop is that, now, library A is at the mercy of library B being a good citizen (and vice versa)\r\n\r\nWhat do you mean? Do you mean that some library may use blocking calls?\r\n\r\nThe main use cases I think of:\r\n1. Have an async DNS library, that I might use for whatever I want (e.g. a HTTP client)\r\n2. I may want to build a HTTP proxy, that's basically a combination of HTTP client and HTTP server\r\n3. Even just writing a hander for HTTP server library is kinda composition of state machines which is not trivial to write with mio too (for example http handler should probably have shared mutable state, which is stored inside of `mio::Handler` implementation, but to have HTTP work we must use handler from HTTP server library)\r\n\r\nCurrently I can only put each library in its own thread and send messages between. I find this approach too wasteful. Especially for (3). Is it what you propose as:\r\n\r\n> I think that generally, libraries should encapsulate their own event loop and expose thread-safe APIs that can be used wherever.\r\n\r\n "}}