{"action":"created","issue":{"url":"https://api.github.com/repos/ruby-concurrency/concurrent-ruby/issues/494","labels_url":"https://api.github.com/repos/ruby-concurrency/concurrent-ruby/issues/494/labels{/name}","comments_url":"https://api.github.com/repos/ruby-concurrency/concurrent-ruby/issues/494/comments","events_url":"https://api.github.com/repos/ruby-concurrency/concurrent-ruby/issues/494/events","html_url":"https://github.com/ruby-concurrency/concurrent-ruby/issues/494","id":126523499,"number":494,"title":"concurrent-edge: reading from a closed channel (timing issue)","user":{"login":"kylewolfe","id":5065665,"avatar_url":"https://avatars.githubusercontent.com/u/5065665?v=3","gravatar_id":"","url":"https://api.github.com/users/kylewolfe","html_url":"https://github.com/kylewolfe","followers_url":"https://api.github.com/users/kylewolfe/followers","following_url":"https://api.github.com/users/kylewolfe/following{/other_user}","gists_url":"https://api.github.com/users/kylewolfe/gists{/gist_id}","starred_url":"https://api.github.com/users/kylewolfe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylewolfe/subscriptions","organizations_url":"https://api.github.com/users/kylewolfe/orgs","repos_url":"https://api.github.com/users/kylewolfe/repos","events_url":"https://api.github.com/users/kylewolfe/events{/privacy}","received_events_url":"https://api.github.com/users/kylewolfe/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-01-13T21:47:35Z","updated_at":"2016-01-15T06:24:07Z","closed_at":null,"body":"While writing a simple concurrent client for a RESTful service, I ran in to this scenario. The current code hangs on the last take on the channel, because take is performed before the channel is closed. Uncomment the sleep and the take operation returns a nil (as it should in both cases, IMO to avoid having to always use a 'done' channel. FYI, Golang does not block on reading of a closed channel, see: http://play.golang.org/p/WZelemy9Up)\r\n\r\n```ruby\r\nrequire 'concurrent-edge'\r\n\r\nresp_chan = Concurrent::Channel.new\r\nrow_chan = Concurrent::Channel.new\r\n\r\n# create caller worker\r\nConcurrent::Channel.go {\r\n  resp_chan << \"1\"\r\n  resp_chan << \"2\"\r\n\r\n  resp_chan.close\r\n}\r\n\r\n# create response worker\r\nConcurrent::Channel.go {\r\n  resp_chan.each{ |resp|\r\n    row_chan << resp + \"-1\"\r\n    row_chan << resp + \"-2\"\r\n    row_chan << resp + \"-3\"\r\n  }\r\n  row_chan.close\r\n}\r\n\r\np row_chan.take\r\np row_chan.take\r\np row_chan.take\r\np row_chan.take\r\np row_chan.take\r\np row_chan.take\r\n#sleep(1)\r\np row_chan.take\r\n```"},"comment":{"url":"https://api.github.com/repos/ruby-concurrency/concurrent-ruby/issues/comments/171881638","html_url":"https://github.com/ruby-concurrency/concurrent-ruby/issues/494#issuecomment-171881638","issue_url":"https://api.github.com/repos/ruby-concurrency/concurrent-ruby/issues/494","id":171881638,"user":{"login":"jdantonio","id":173910,"avatar_url":"https://avatars.githubusercontent.com/u/173910?v=3","gravatar_id":"","url":"https://api.github.com/users/jdantonio","html_url":"https://github.com/jdantonio","followers_url":"https://api.github.com/users/jdantonio/followers","following_url":"https://api.github.com/users/jdantonio/following{/other_user}","gists_url":"https://api.github.com/users/jdantonio/gists{/gist_id}","starred_url":"https://api.github.com/users/jdantonio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdantonio/subscriptions","organizations_url":"https://api.github.com/users/jdantonio/orgs","repos_url":"https://api.github.com/users/jdantonio/repos","events_url":"https://api.github.com/users/jdantonio/events{/privacy}","received_events_url":"https://api.github.com/users/jdantonio/received_events","type":"User","site_admin":false},"created_at":"2016-01-15T06:24:07Z","updated_at":"2016-01-15T06:24:07Z","body":"Thank you! That's a huge help--now I know exactly where to look.\r\n\r\nThat's an excellent suggestion regarding deadlock detection. This channel implementation is very raw. I started working on it as I was learning Go for fun. It's a long way from being production ready. Please keep the feedback and suggestions coming! It's much appreciated."}}