{"action":"created","issue":{"url":"https://api.github.com/repos/mattn/anko/issues/285","repository_url":"https://api.github.com/repos/mattn/anko","labels_url":"https://api.github.com/repos/mattn/anko/issues/285/labels{/name}","comments_url":"https://api.github.com/repos/mattn/anko/issues/285/comments","events_url":"https://api.github.com/repos/mattn/anko/issues/285/events","html_url":"https://github.com/mattn/anko/pull/285","id":392495341,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM5NzUzNDQ1","number":285,"title":"Add context so we can interrupt channels","user":{"login":"alaingilbert","id":886683,"node_id":"MDQ6VXNlcjg4NjY4Mw==","avatar_url":"https://avatars3.githubusercontent.com/u/886683?v=4","gravatar_id":"","url":"https://api.github.com/users/alaingilbert","html_url":"https://github.com/alaingilbert","followers_url":"https://api.github.com/users/alaingilbert/followers","following_url":"https://api.github.com/users/alaingilbert/following{/other_user}","gists_url":"https://api.github.com/users/alaingilbert/gists{/gist_id}","starred_url":"https://api.github.com/users/alaingilbert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alaingilbert/subscriptions","organizations_url":"https://api.github.com/users/alaingilbert/orgs","repos_url":"https://api.github.com/users/alaingilbert/repos","events_url":"https://api.github.com/users/alaingilbert/events{/privacy}","received_events_url":"https://api.github.com/users/alaingilbert/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":20,"created_at":"2018-12-19T08:45:21Z","updated_at":"2018-12-20T07:45:47Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/mattn/anko/pulls/285","html_url":"https://github.com/mattn/anko/pull/285","diff_url":"https://github.com/mattn/anko/pull/285.diff","patch_url":"https://github.com/mattn/anko/pull/285.patch"},"body":"**Problem:** When you have a script that ends with \"receive from chan\", the script get stuck there forever, and `vm.Interrupt(env)` is unable to cancel the execution of that script.\r\nExample:\r\n```\r\nch = make(chan string)\r\n<-ch\r\n```\r\n**Solution:** I added an optional `(e *Env) SetContext(context.Context) *Env` function.\r\nWhen you give a context to this function, it will change how it interrupt the code inside the VM.\r\nThere is 2 main differences\r\n- The main loop will check for each statement if there is a context, and if it should exit the loop.\r\n- The channels will now \"select\" between the `ctx.Done()` and the channel, instead of just waiting forever on the `ch.Recv()`\r\n\r\nIf there is no context, none of the above apply, the code execute as it was before.\r\n\r\nThe test [TestInterruptChannelWithContext](https://github.com/mattn/anko/pull/285/files#diff-d11f06e0aa37028f414640b3ea88c2acR827) will break the current master"},"comment":{"url":"https://api.github.com/repos/mattn/anko/issues/comments/448904167","html_url":"https://github.com/mattn/anko/pull/285#issuecomment-448904167","issue_url":"https://api.github.com/repos/mattn/anko/issues/285","id":448904167,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0ODkwNDE2Nw==","user":{"login":"alaingilbert","id":886683,"node_id":"MDQ6VXNlcjg4NjY4Mw==","avatar_url":"https://avatars3.githubusercontent.com/u/886683?v=4","gravatar_id":"","url":"https://api.github.com/users/alaingilbert","html_url":"https://github.com/alaingilbert","followers_url":"https://api.github.com/users/alaingilbert/followers","following_url":"https://api.github.com/users/alaingilbert/following{/other_user}","gists_url":"https://api.github.com/users/alaingilbert/gists{/gist_id}","starred_url":"https://api.github.com/users/alaingilbert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alaingilbert/subscriptions","organizations_url":"https://api.github.com/users/alaingilbert/orgs","repos_url":"https://api.github.com/users/alaingilbert/repos","events_url":"https://api.github.com/users/alaingilbert/events{/privacy}","received_events_url":"https://api.github.com/users/alaingilbert/received_events","type":"User","site_admin":false},"created_at":"2018-12-20T07:45:47Z","updated_at":"2018-12-20T07:45:47Z","author_association":"NONE","body":"I'm not sure where I could add a test to reach the select branches.\r\nAny ideas ?"}}
{"actor":{"display_login":"alaingilbert"}}