{"action":"created","issue":{"url":"https://api.github.com/repos/apollographql/graphql-subscriptions/issues/143","repository_url":"https://api.github.com/repos/apollographql/graphql-subscriptions","labels_url":"https://api.github.com/repos/apollographql/graphql-subscriptions/issues/143/labels{/name}","comments_url":"https://api.github.com/repos/apollographql/graphql-subscriptions/issues/143/comments","events_url":"https://api.github.com/repos/apollographql/graphql-subscriptions/issues/143/events","html_url":"https://github.com/apollographql/graphql-subscriptions/issues/143","id":302028738,"number":143,"title":"iterable.return() is not sufficient to clean up subscriptions","user":{"login":"jquense","id":339286,"avatar_url":"https://avatars2.githubusercontent.com/u/339286?v=4","gravatar_id":"","url":"https://api.github.com/users/jquense","html_url":"https://github.com/jquense","followers_url":"https://api.github.com/users/jquense/followers","following_url":"https://api.github.com/users/jquense/following{/other_user}","gists_url":"https://api.github.com/users/jquense/gists{/gist_id}","starred_url":"https://api.github.com/users/jquense/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jquense/subscriptions","organizations_url":"https://api.github.com/users/jquense/orgs","repos_url":"https://api.github.com/users/jquense/repos","events_url":"https://api.github.com/users/jquense/events{/privacy}","received_events_url":"https://api.github.com/users/jquense/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-03-03T20:16:07Z","updated_at":"2018-04-02T00:17:25Z","closed_at":null,"author_association":"NONE","body":"Hey there 👋 This is perhaps a bug report and a bit of a question about how ya;'ll have implemented this. \r\n\r\nWe've been working on our own semi-internal implementation of subscriptions for graphql and come across an issue handling the pub-sub case, one that seems like ya'll suffer from as well (unless i'm missing something)\r\n\r\nThe crux of the issue is that `iterable.return()` doesn't get called when an iterable hasn't started. which means once you've used language level constructs to map or filter an iterable it'll never clean up unless it's already had a value pulled\r\n\r\nFollowing will run in Chrome if you paste it into a console:\r\n\r\n```js\r\nlet f = (()=> {\r\n  let i = 0\r\n  return {\r\n    next() {\r\n      return Promise.resolve({ value: i++, done:  i >= 4 })\r\n    },\r\n    return() {\r\n      console.log('return!')\r\n      return Promise.resolve({ value: undefined, done: true });\r\n    },\r\n    throw(error) {\r\n      return Promise.reject(error);\r\n    },\r\n    [Symbol.asyncIterator]() {\r\n      return this\r\n    }\r\n  }\r\n})()\r\n\r\nasync function* addOne() {\r\n  for await (const val of f) yield val + 1;\r\n}\r\n\r\nawait addOne().return();\r\n```\r\n\r\nThe practical problem is that if you disconnect or unsubscribe from a subscription before it pushes a value, the underlying pup-sub will never clean itself up.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/apollographql/graphql-subscriptions/issues/comments/377827894","html_url":"https://github.com/apollographql/graphql-subscriptions/issues/143#issuecomment-377827894","issue_url":"https://api.github.com/repos/apollographql/graphql-subscriptions/issues/143","id":377827894,"user":{"login":"jedwards1211","id":1448194,"avatar_url":"https://avatars0.githubusercontent.com/u/1448194?v=4","gravatar_id":"","url":"https://api.github.com/users/jedwards1211","html_url":"https://github.com/jedwards1211","followers_url":"https://api.github.com/users/jedwards1211/followers","following_url":"https://api.github.com/users/jedwards1211/following{/other_user}","gists_url":"https://api.github.com/users/jedwards1211/gists{/gist_id}","starred_url":"https://api.github.com/users/jedwards1211/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jedwards1211/subscriptions","organizations_url":"https://api.github.com/users/jedwards1211/orgs","repos_url":"https://api.github.com/users/jedwards1211/repos","events_url":"https://api.github.com/users/jedwards1211/events{/privacy}","received_events_url":"https://api.github.com/users/jedwards1211/received_events","type":"User","site_admin":false},"created_at":"2018-04-02T00:17:25Z","updated_at":"2018-04-02T00:17:25Z","author_association":"NONE","body":"@jquense I think the title of this issue isn't really correct, `return()` is perfectly sufficient to clean up subscriptions, the async iterables just have to be written correctly."}}
{"actor":{"display_login":"jedwards1211"}}