{"action":"created","issue":{"url":"https://api.github.com/repos/tokio-rs/tokio/issues/328","repository_url":"https://api.github.com/repos/tokio-rs/tokio","labels_url":"https://api.github.com/repos/tokio-rs/tokio/issues/328/labels{/name}","comments_url":"https://api.github.com/repos/tokio-rs/tokio/issues/328/comments","events_url":"https://api.github.com/repos/tokio-rs/tokio/issues/328/events","html_url":"https://github.com/tokio-rs/tokio/pull/328","id":318765769,"number":328,"title":"add Runtime::block_on API","user":{"login":"danburkert","id":160242,"avatar_url":"https://avatars0.githubusercontent.com/u/160242?v=4","gravatar_id":"","url":"https://api.github.com/users/danburkert","html_url":"https://github.com/danburkert","followers_url":"https://api.github.com/users/danburkert/followers","following_url":"https://api.github.com/users/danburkert/following{/other_user}","gists_url":"https://api.github.com/users/danburkert/gists{/gist_id}","starred_url":"https://api.github.com/users/danburkert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danburkert/subscriptions","organizations_url":"https://api.github.com/users/danburkert/orgs","repos_url":"https://api.github.com/users/danburkert/repos","events_url":"https://api.github.com/users/danburkert/events{/privacy}","received_events_url":"https://api.github.com/users/danburkert/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-04-30T00:57:15Z","updated_at":"2018-04-30T05:43:16Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/tokio-rs/tokio/pulls/328","html_url":"https://github.com/tokio-rs/tokio/pull/328","diff_url":"https://github.com/tokio-rs/tokio/pull/328.diff","patch_url":"https://github.com/tokio-rs/tokio/pull/328.patch"},"body":"Adds the `Runtime::block_on` and `tokio_threadpool::Sender::block_on`\r\nmethods, which take a future and run it to completion on the Tokio\r\nruntime. The future provided to these methods must be `Send`, but not\r\n`'static` (unlike `Runtime::spawn`). If the future panics, the panic is\r\npropagated to the calling thread.\r\n\r\nThe API is pretty straightforward, however there are two things that\r\nmight need tweaking:\r\n\r\n1) `Sender::block_on` returns a nested `Result` in order to indicate a\r\n   threadpool error. This is a bit awkward, but I'm not sure what will\r\n   be the preferred way to indicate a failure here.  This isn't a\r\n   problem for `Runtime::block_on`, because the existing convention is\r\n   to panic on threadpool error.\r\n\r\n2) the API docs warn not to call `block_on` from an async context.\r\n   This could be enforced by asserting or debug asserting that the\r\n   calling thread is not a tokio-threadpool worker, but that check is\r\n   not included in this commit."},"comment":{"url":"https://api.github.com/repos/tokio-rs/tokio/issues/comments/385317171","html_url":"https://github.com/tokio-rs/tokio/pull/328#issuecomment-385317171","issue_url":"https://api.github.com/repos/tokio-rs/tokio/issues/328","id":385317171,"user":{"login":"danburkert","id":160242,"avatar_url":"https://avatars0.githubusercontent.com/u/160242?v=4","gravatar_id":"","url":"https://api.github.com/users/danburkert","html_url":"https://github.com/danburkert","followers_url":"https://api.github.com/users/danburkert/followers","following_url":"https://api.github.com/users/danburkert/following{/other_user}","gists_url":"https://api.github.com/users/danburkert/gists{/gist_id}","starred_url":"https://api.github.com/users/danburkert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danburkert/subscriptions","organizations_url":"https://api.github.com/users/danburkert/orgs","repos_url":"https://api.github.com/users/danburkert/repos","events_url":"https://api.github.com/users/danburkert/events{/privacy}","received_events_url":"https://api.github.com/users/danburkert/received_events","type":"User","site_admin":false},"created_at":"2018-04-30T05:43:16Z","updated_at":"2018-04-30T05:43:16Z","author_association":"CONTRIBUTOR","body":"> 1. This seems fine. Sender::block_on can have a more awkward API. It is lower level.\r\n\r\nYeah, that's what I was thinking as well.  Long term it may be good to rename `SpawnError` to something more general like `ThreadpoolError`.\r\n\r\n> I would call tokio_executor::enter() at the start of block_on. This should achieve the correct before for the general case.\r\n\r\nDone."}}
{"actor":{"display_login":"danburkert"}}