{"action":"created","issue":{"url":"https://api.github.com/repos/ReactiveX/RxJava/issues/4205","repository_url":"https://api.github.com/repos/ReactiveX/RxJava","labels_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/4205/labels{/name}","comments_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/4205/comments","events_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/4205/events","html_url":"https://github.com/ReactiveX/RxJava/issues/4205","id":165775898,"number":4205,"title":"Option for Subscription to add self to CompositeSubscription","user":{"login":"bakua","id":494667,"avatar_url":"https://avatars.githubusercontent.com/u/494667?v=3","gravatar_id":"","url":"https://api.github.com/users/bakua","html_url":"https://github.com/bakua","followers_url":"https://api.github.com/users/bakua/followers","following_url":"https://api.github.com/users/bakua/following{/other_user}","gists_url":"https://api.github.com/users/bakua/gists{/gist_id}","starred_url":"https://api.github.com/users/bakua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bakua/subscriptions","organizations_url":"https://api.github.com/users/bakua/orgs","repos_url":"https://api.github.com/users/bakua/repos","events_url":"https://api.github.com/users/bakua/events{/privacy}","received_events_url":"https://api.github.com/users/bakua/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ReactiveX/RxJava/labels/Question","name":"Question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-07-15T12:25:50Z","updated_at":"2016-07-16T05:37:03Z","closed_at":null,"body":"Hey, when managing multiple subscriptions I am a little bit frustrated with a confused code the `CompositeSubscription` causes.\r\nIn following example you can see that the Observable itself is a little bit hidden.\r\n```    \r\nCompositeSubscription compositeSubscription = new CompositeSubscription();\r\ncompositeSubscription.add(Observable.just(\"test\")\r\n    .subscribe(new Subscriber<String>() {\r\n            @Override\r\n            public void onCompleted() {\r\n\r\n            }\r\n\r\n            @Override\r\n            public void onError(Throwable e) {\r\n\r\n            }\r\n\r\n            @Override\r\n            public void onNext(String s) {\r\n\r\n            }\r\n        }));\r\n```\r\n\r\nIt would be great to have something convinient. For example something as simple as one method in Subscriber\r\n```\r\n    public void addTo(@NonNull CompositeSubscription compositeSubscription) {\r\n        compositeSubscription.add(this);\r\n    } \r\n```\r\nThis way the previous example would change into:\r\n```\r\nCompositeSubscription compositeSubscription = new CompositeSubscription();\r\nObservable.just(\"test\")\r\n   .subscribe(new Subscriber<String>() {\r\n            @Override\r\n            public void onCompleted() {\r\n\r\n            }\r\n\r\n            @Override\r\n            public void onError(Throwable e) {\r\n\r\n            }\r\n\r\n            @Override\r\n            public void onNext(String s) {\r\n\r\n            }\r\n        })\r\n   .addTo(compositeSubscription);\r\n```\r\nI am more than happy to make a pull request for such a thing.\r\n\r\nThanks.\r\nbakua"},"comment":{"url":"https://api.github.com/repos/ReactiveX/RxJava/issues/comments/233109624","html_url":"https://github.com/ReactiveX/RxJava/issues/4205#issuecomment-233109624","issue_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/4205","id":233109624,"user":{"login":"bakua","id":494667,"avatar_url":"https://avatars.githubusercontent.com/u/494667?v=3","gravatar_id":"","url":"https://api.github.com/users/bakua","html_url":"https://github.com/bakua","followers_url":"https://api.github.com/users/bakua/followers","following_url":"https://api.github.com/users/bakua/following{/other_user}","gists_url":"https://api.github.com/users/bakua/gists{/gist_id}","starred_url":"https://api.github.com/users/bakua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bakua/subscriptions","organizations_url":"https://api.github.com/users/bakua/orgs","repos_url":"https://api.github.com/users/bakua/repos","events_url":"https://api.github.com/users/bakua/events{/privacy}","received_events_url":"https://api.github.com/users/bakua/received_events","type":"User","site_admin":false},"created_at":"2016-07-16T05:37:03Z","updated_at":"2016-07-16T05:37:03Z","body":"I see, thanks. I took an inspiration from RxSwift where such an option exists.\r\n```\r\nObservable<Int>.interval(1.0, scheduler: MainScheduler.instance)     \r\n    .map({num in num * 10})\r\n    .subscribeNext({num in print(num)})\r\n    .addDisposableTo(disposeBag)\r\n```\r\nBut if it is not possible to have it in RxJava, feel free to close this issue."}}
{"actor":{"display_login":"bakua"}}