{"action":"created","issue":{"url":"https://api.github.com/repos/ReactiveX/RxAndroid/issues/214","labels_url":"https://api.github.com/repos/ReactiveX/RxAndroid/issues/214/labels{/name}","comments_url":"https://api.github.com/repos/ReactiveX/RxAndroid/issues/214/comments","events_url":"https://api.github.com/repos/ReactiveX/RxAndroid/issues/214/events","html_url":"https://github.com/ReactiveX/RxAndroid/issues/214","id":99839373,"number":214,"title":"Observable.interval(1, 1, TimeUnit.SECONDS, mainThread()) continues execution if unsubscribed from onNext","user":{"login":"konmik","id":8560582,"avatar_url":"https://avatars.githubusercontent.com/u/8560582?v=3","gravatar_id":"","url":"https://api.github.com/users/konmik","html_url":"https://github.com/konmik","followers_url":"https://api.github.com/users/konmik/followers","following_url":"https://api.github.com/users/konmik/following{/other_user}","gists_url":"https://api.github.com/users/konmik/gists{/gist_id}","starred_url":"https://api.github.com/users/konmik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/konmik/subscriptions","organizations_url":"https://api.github.com/users/konmik/orgs","repos_url":"https://api.github.com/users/konmik/repos","events_url":"https://api.github.com/users/konmik/events{/privacy}","received_events_url":"https://api.github.com/users/konmik/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-08-08T22:30:42Z","updated_at":"2015-08-09T12:26:48Z","closed_at":"2015-08-09T02:31:28Z","body":"Subj.\r\n\r\nReproduction:\r\n\r\n        final AtomicReference<Subscription> subscriptionAtomicReference = new AtomicReference<>();\r\n        subscriptionAtomicReference.set(Observable.interval(1, 1, TimeUnit.SECONDS, mainThread())\r\n            .doOnNext(new Action1<Long>() {\r\n                @Override\r\n                public void call(Long value) {\r\n                    Log.v(\"INTERVAL\", \"\" + value);\r\n                    subscriptionAtomicReference.get().unsubscribe();\r\n                }\r\n            })\r\n            .subscribe());\r\n\r\nOutput:\r\n\r\nINTERVAL﹕ 0\r\nINTERVAL﹕ 1\r\nINTERVAL﹕ 2\r\nINTERVAL﹕ 3\r\netc.\r\n\r\n\r\nWorkaround:\r\n\r\n        final AtomicReference<Subscription> subscriptionAtomicReference = new AtomicReference<>();\r\n        subscriptionAtomicReference.set(Observable.interval(1, 1, TimeUnit.SECONDS)\r\n            .observeOn(mainThread())\r\n            .doOnNext(new Action1<Long>() {\r\n                @Override\r\n                public void call(Long value) {\r\n                    Log.v(\"INTERVAL\", \"\" + value);\r\n                    subscriptionAtomicReference.get().unsubscribe();\r\n                }\r\n            })\r\n            .subscribe());\r\n\r\nOutput:\r\n\r\nINTERVAL﹕ 0\r\n"},"comment":{"url":"https://api.github.com/repos/ReactiveX/RxAndroid/issues/comments/129174556","html_url":"https://github.com/ReactiveX/RxAndroid/issues/214#issuecomment-129174556","issue_url":"https://api.github.com/repos/ReactiveX/RxAndroid/issues/214","id":129174556,"user":{"login":"dlew","id":514850,"avatar_url":"https://avatars.githubusercontent.com/u/514850?v=3","gravatar_id":"","url":"https://api.github.com/users/dlew","html_url":"https://github.com/dlew","followers_url":"https://api.github.com/users/dlew/followers","following_url":"https://api.github.com/users/dlew/following{/other_user}","gists_url":"https://api.github.com/users/dlew/gists{/gist_id}","starred_url":"https://api.github.com/users/dlew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlew/subscriptions","organizations_url":"https://api.github.com/users/dlew/orgs","repos_url":"https://api.github.com/users/dlew/repos","events_url":"https://api.github.com/users/dlew/events{/privacy}","received_events_url":"https://api.github.com/users/dlew/received_events","type":"User","site_admin":false},"created_at":"2015-08-09T12:26:48Z","updated_at":"2015-08-09T12:26:48Z","body":"@akarnokd Actually, another question (while we're on correctness). The linked post wraps the `ScheduledAction` with another check for `isUnsubscribed()` - would that be correct here? I.e.:\r\n\r\n```java\r\npublic Subscription schedule(Action0 action, long delayTime, TimeUnit unit) {\r\n    if (compositeSubscription.isUnsubscribed()) {\r\n        return Subscriptions.unsubscribed();\r\n    }\r\n\r\n    action = RxAndroidPlugins.getInstance().getSchedulersHook().onSchedule(action);\r\n\r\n    final ScheduledAction scheduledAction = new ScheduledAction(action);\r\n    scheduledAction.addParent(compositeSubscription);\r\n    compositeSubscription.add(scheduledAction);\r\n\r\n    final Runnable r = new Runnable() {\r\n        @Override\r\n        public void run() {\r\n            if (!scheduledAction.isUnsubscribed()) {\r\n                scheduledAction.run();\r\n            }\r\n        }\r\n    };\r\n\r\n    handler.postDelayed(r, unit.toMillis(delayTime));\r\n\r\n    scheduledAction.add(Subscriptions.create(new Action0() {\r\n        @Override\r\n        public void call() {\r\n            handler.removeCallbacks(r);\r\n        }\r\n    }));\r\n\r\n    return scheduledAction;\r\n}\r\n```"}}