{"action":"created","issue":{"url":"https://api.github.com/repos/ReactiveX/RxJS/issues/57","labels_url":"https://api.github.com/repos/ReactiveX/RxJS/issues/57/labels{/name}","comments_url":"https://api.github.com/repos/ReactiveX/RxJS/issues/57/comments","events_url":"https://api.github.com/repos/ReactiveX/RxJS/issues/57/events","html_url":"https://github.com/ReactiveX/RxJS/issues/57","id":92505396,"number":57,"title":"Switch Observable signature to Generator in Generator out","user":{"login":"blesh","id":1540597,"avatar_url":"https://avatars.githubusercontent.com/u/1540597?v=3","gravatar_id":"","url":"https://api.github.com/users/blesh","html_url":"https://github.com/blesh","followers_url":"https://api.github.com/users/blesh/followers","following_url":"https://api.github.com/users/blesh/following{/other_user}","gists_url":"https://api.github.com/users/blesh/gists{/gist_id}","starred_url":"https://api.github.com/users/blesh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blesh/subscriptions","organizations_url":"https://api.github.com/users/blesh/orgs","repos_url":"https://api.github.com/users/blesh/repos","events_url":"https://api.github.com/users/blesh/events{/privacy}","received_events_url":"https://api.github.com/users/blesh/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-01T23:18:27Z","updated_at":"2015-07-04T22:32:13Z","closed_at":"2015-07-04T22:32:13Z","body":"Per #28, we need to match observable spec defined at http://github.com/zenparsing/es-observable\r\n\r\nAfter discussion with @jhusain, it's been determined that the signature should be \"generator in generator out\", and that Generator should have an additional `dispose` method on it.\r\n\r\nHere's the basics for purposes of this issue (the @zenparsing repo will be the \"official\" version of the spec though, it's just not updated as of the time of this issue creation):\r\n\r\n```TypeScript\r\n// rough interface (could be more \"genericky\", I suppose)\r\ninterface Generator {\r\n  next(value:any):IteratorResult<any>\r\n  return(value:any):IteratorResult<any>\r\n  throw(value:any):IteratorResult<any>\r\n  dispose():void\r\n}\r\n\r\nlet subscription:Generator = myObservable.subscribe(observer:Generator);\r\n```\r\n\r\nWith this there will be three methods of unsubscribing:\r\n\r\n1. `subscription.return(x)` - signal success to the consumer, then clean up.\r\n2. `subscription.throw(err)` - signal an error to the consumer, then clean up.\r\n3. `subscription.dispose()` - just clean up\r\n\r\n\r\n### Why?\r\n\r\nThis enables the support of generator functions as observers:\r\n\r\n```js\r\nmyObservable.subscribe(prime(function* () {\r\n  try {\r\n    while(true) {\r\n      var value = yield; // nexted value\r\n      doSomething(value);\r\n    }\r\n  } catch(err) {\r\n    someErrorHappened(err)\r\n  } finally {\r\n    // clean up\r\n  }\r\n}));\r\n```\r\n\r\nwhich would be (roughly) synonymous with:\r\n\r\n```js\r\nmyObservable.subscribe({\r\n  next(value) { doSomething(value); },\r\n  throw(err) { someErrorHappened(err); },\r\n  dispose() { completedSuccessfully(); }\r\n});\r\n```\r\n\r\nBoth will work, the latter is preferred in most cases, but the primed generator pattern can prove useful for things like parsers or other state machines that may built up values to clean up as it processes incoming values.\r\n\r\n\r\n\\* Note: `prime` is a function that pumps one \"next\" value at the generator to get it started, since generators are initialized lazily with the first `next` call to their returned iterators.\r\n\r\n/cc @jhusain\r\n\r\nref: \r\n\r\n- https://github.com/zenparsing/es-observable/issues/32\r\n- https://github.com/zenparsing/es-observable/issues/33"},"comment":{"url":"https://api.github.com/repos/ReactiveX/RxJS/issues/comments/118560662","html_url":"https://github.com/ReactiveX/RxJS/issues/57#issuecomment-118560662","issue_url":"https://api.github.com/repos/ReactiveX/RxJS/issues/57","id":118560662,"user":{"login":"blesh","id":1540597,"avatar_url":"https://avatars.githubusercontent.com/u/1540597?v=3","gravatar_id":"","url":"https://api.github.com/users/blesh","html_url":"https://github.com/blesh","followers_url":"https://api.github.com/users/blesh/followers","following_url":"https://api.github.com/users/blesh/following{/other_user}","gists_url":"https://api.github.com/users/blesh/gists{/gist_id}","starred_url":"https://api.github.com/users/blesh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blesh/subscriptions","organizations_url":"https://api.github.com/users/blesh/orgs","repos_url":"https://api.github.com/users/blesh/repos","events_url":"https://api.github.com/users/blesh/events{/privacy}","received_events_url":"https://api.github.com/users/blesh/received_events","type":"User","site_admin":false},"created_at":"2015-07-04T22:32:13Z","updated_at":"2015-07-04T22:32:13Z","body":"I no longer think this is the appropriate direction for this library or the observable spec. Closing for now. See discussion here: https://github.com/zenparsing/es-observable/issues/35#issuecomment-118557639"}}