{"action":"created","issue":{"url":"https://api.github.com/repos/Reactive-Extensions/RxJS/issues/1011","labels_url":"https://api.github.com/repos/Reactive-Extensions/RxJS/issues/1011/labels{/name}","comments_url":"https://api.github.com/repos/Reactive-Extensions/RxJS/issues/1011/comments","events_url":"https://api.github.com/repos/Reactive-Extensions/RxJS/issues/1011/events","html_url":"https://github.com/Reactive-Extensions/RxJS/issues/1011","id":114465666,"number":1011,"title":"Code duplication in .subscribe()","user":{"login":"Yagger","id":1056226,"avatar_url":"https://avatars.githubusercontent.com/u/1056226?v=3","gravatar_id":"","url":"https://api.github.com/users/Yagger","html_url":"https://github.com/Yagger","followers_url":"https://api.github.com/users/Yagger/followers","following_url":"https://api.github.com/users/Yagger/following{/other_user}","gists_url":"https://api.github.com/users/Yagger/gists{/gist_id}","starred_url":"https://api.github.com/users/Yagger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yagger/subscriptions","organizations_url":"https://api.github.com/users/Yagger/orgs","repos_url":"https://api.github.com/users/Yagger/repos","events_url":"https://api.github.com/users/Yagger/events{/privacy}","received_events_url":"https://api.github.com/users/Yagger/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-01T11:41:31Z","updated_at":"2015-11-02T01:40:30Z","closed_at":null,"body":"How could we avoid code duplication if the same code needs to run disregarding what function is called (onNext, onError or onComplete).\r\n\r\nIn the following example, `this.loading.next(false)` is called in all scenarios - on success, on error and on complete.\r\nShould be a way to add something like `finally()` function as optional fourth parameter, that will contain the code to be executed whatever happens.\r\n```\r\n.subscribe(\r\n    (results: SearchResult[]) => {\r\n        this.loading.next(false); // <== duplicated line of code\r\n        this.results.next(results);\r\n    },\r\n    (error: any) => {\r\n        console.log(error);\r\n        this.loading.next(false); // <== duplicated line of code\r\n    },\r\n    () => {\r\n        this.loading.next(false); // <== duplicated line of code\r\n    }\r\n);\r\n```"},"comment":{"url":"https://api.github.com/repos/Reactive-Extensions/RxJS/issues/comments/152887147","html_url":"https://github.com/Reactive-Extensions/RxJS/issues/1011#issuecomment-152887147","issue_url":"https://api.github.com/repos/Reactive-Extensions/RxJS/issues/1011","id":152887147,"user":{"login":"mattpodwysocki","id":49051,"avatar_url":"https://avatars.githubusercontent.com/u/49051?v=3","gravatar_id":"","url":"https://api.github.com/users/mattpodwysocki","html_url":"https://github.com/mattpodwysocki","followers_url":"https://api.github.com/users/mattpodwysocki/followers","following_url":"https://api.github.com/users/mattpodwysocki/following{/other_user}","gists_url":"https://api.github.com/users/mattpodwysocki/gists{/gist_id}","starred_url":"https://api.github.com/users/mattpodwysocki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattpodwysocki/subscriptions","organizations_url":"https://api.github.com/users/mattpodwysocki/orgs","repos_url":"https://api.github.com/users/mattpodwysocki/repos","events_url":"https://api.github.com/users/mattpodwysocki/events{/privacy}","received_events_url":"https://api.github.com/users/mattpodwysocki/received_events","type":"User","site_admin":false},"created_at":"2015-11-02T01:40:30Z","updated_at":"2015-11-02T01:40:30Z","body":"@Yagger yes, that's the point of `finally` where you can do something right as `onCompleted` or `onError` has been hit. I'm not sure why you are also calling this in `onNext`."}}