{"action":"created","issue":{"url":"https://api.github.com/repos/ubolonton/js-csp/issues/129","repository_url":"https://api.github.com/repos/ubolonton/js-csp","labels_url":"https://api.github.com/repos/ubolonton/js-csp/issues/129/labels{/name}","comments_url":"https://api.github.com/repos/ubolonton/js-csp/issues/129/comments","events_url":"https://api.github.com/repos/ubolonton/js-csp/issues/129/events","html_url":"https://github.com/ubolonton/js-csp/issues/129","id":240556705,"number":129,"title":"Major bug: proc is yielding first pending value when channel is closed but skipping the rest","user":{"login":"Cpt0r","id":8690075,"avatar_url":"https://avatars2.githubusercontent.com/u/8690075?v=4","gravatar_id":"","url":"https://api.github.com/users/Cpt0r","html_url":"https://github.com/Cpt0r","followers_url":"https://api.github.com/users/Cpt0r/followers","following_url":"https://api.github.com/users/Cpt0r/following{/other_user}","gists_url":"https://api.github.com/users/Cpt0r/gists{/gist_id}","starred_url":"https://api.github.com/users/Cpt0r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Cpt0r/subscriptions","organizations_url":"https://api.github.com/users/Cpt0r/orgs","repos_url":"https://api.github.com/users/Cpt0r/repos","events_url":"https://api.github.com/users/Cpt0r/events{/privacy}","received_events_url":"https://api.github.com/users/Cpt0r/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":34,"created_at":"2017-07-05T07:03:04Z","updated_at":"2017-07-24T01:20:39Z","closed_at":"2017-07-23T03:31:41Z","body":"Here's a simple example to reproduce the unexpected - and arguably wrong - behaviour:\r\n\r\n```\r\n  const ch = csp.chan()\r\n\r\n  csp.go( function* ( ) {\r\n    while ( true ) {\r\n      const value = yield ch\r\n      // OR\r\n      // const { value } = yield csp.alts( [ ch ] )\r\n\r\n      console.log( 'closed:', ch.closed, ', value:', value );\r\n\r\n      if ( value === csp.CLOSED ) {\r\n        break\r\n      }\r\n    }\r\n  } )\r\n\r\n  csp.putAsync( ch, 'foo' )\r\n  csp.putAsync( ch, 'bar' )\r\n  csp.putAsync( ch, 'baz' )\r\n  ch.close()\r\n```\r\n\r\nOutput:\r\n> closed: true, value: foo\r\nclosed: true, value: null\r\n\r\nIf you put the values and close the channel **before** launching the proc then the output is as expected:\r\n> closed: true, value: null\r\n\r\nReal world scenario:\r\nBecause js-csp has no `.kill()` method (as per https://github.com/ubolonton/js-csp/issues/125) we currently use a custom util for creating channels and storing them in a pool.\r\n\r\nThen when we terminate our games we loop through and close them all, thus shutting down all procs (which always check for `value === csp.CLOSED`).\r\n\r\nUnfortunately the procs perform one last step through their loop before exiting and thus attempt to access invalid game state.\r\n\r\nOur only solution is to change all code to rely on `ch.isClosed()` - which is a lot of code at this stage.\r\n\r\nPlease advise ASAP.  I'm happy to debug and fix but need some guidance on where to begin."},"comment":{"url":"https://api.github.com/repos/ubolonton/js-csp/issues/comments/317297354","html_url":"https://github.com/ubolonton/js-csp/issues/129#issuecomment-317297354","issue_url":"https://api.github.com/repos/ubolonton/js-csp/issues/129","id":317297354,"user":{"login":"hung-phan","id":3093244,"avatar_url":"https://avatars1.githubusercontent.com/u/3093244?v=4","gravatar_id":"","url":"https://api.github.com/users/hung-phan","html_url":"https://github.com/hung-phan","followers_url":"https://api.github.com/users/hung-phan/followers","following_url":"https://api.github.com/users/hung-phan/following{/other_user}","gists_url":"https://api.github.com/users/hung-phan/gists{/gist_id}","starred_url":"https://api.github.com/users/hung-phan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hung-phan/subscriptions","organizations_url":"https://api.github.com/users/hung-phan/orgs","repos_url":"https://api.github.com/users/hung-phan/repos","events_url":"https://api.github.com/users/hung-phan/events{/privacy}","received_events_url":"https://api.github.com/users/hung-phan/received_events","type":"User","site_admin":false},"created_at":"2017-07-24T01:20:39Z","updated_at":"2017-07-24T01:20:39Z","body":"@Cpt0r then it will be unbuffered type. See it here https://github.com/ubolonton/js-csp/blob/master/src/csp.core.js#L32"}}
{"actor":{"display_login":"hung-phan"}}