{"action":"created","comment":{"url":"https://api.github.com/repos/ReactiveX/RxAndroid/pulls/comments/73783840","id":73783840,"diff_hunk":"@@ -0,0 +1,85 @@\n+/*\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package io.reactivex.android;\n+\n+import android.os.Looper;\n+import io.reactivex.disposables.Disposable;\n+import java.util.concurrent.atomic.AtomicBoolean;\n+import io.reactivex.android.schedulers.AndroidSchedulers;\n+\n+/**\n+ * A {@linkplain Disposable disposable} which ensures its {@linkplain #onDispose()\n+ * dispose action} is executed on the main thread. When unsubscription occurs on a different\n+ * thread than the main thread, the action is posted to run on the main thread as soon as possible.\n+ * <p>\n+ * Instances of this class are useful in creating observables which interact with APIs that can\n+ * only be used on the main thread, such as UI objects.\n+ * <p>\n+ * A {@link #verifyMainThread() convenience method} is also provided for validating whether code\n+ * is being called on the main thread. Calls to this method along with instances of this class are\n+ * commonly used when creating custom observables using the following pattern:\n+ * <pre><code>\n+ * &#064;Override public void call(Subscriber<? extends T> subscriber) {\n+ *   MainThreadDisposable.verifyMainThread();\n+ *\n+ *   // TODO setup behavior\n+ *\n+ *   subscriber.add(new MainThreadDisposable() {\n+ *     &#064;Override public void onDispose() {\n+ *       // TODO undo behavior\n+ *     }\n+ *   });\n+ * }\n+ * </code></pre>\n+ */\n+public abstract class MainThreadDisposable implements Disposable {\n+    /**\n+     * Verify that the calling thread is the Android main thread.\n+     * <p>\n+     * Calls to this method are usually preconditions for subscription behavior which instances of\n+     * this class later undo. See the class documentation for an example.\n+     *\n+     * @throws IllegalStateException when called from any other thread.\n+     */\n+    public static void verifyMainThread() {\n+        if (Looper.myLooper() != Looper.getMainLooper()) {\n+            throw new IllegalStateException(\n+                \"Expected to be called on the main thread but was \" + Thread.currentThread().getName());\n+        }\n+    }\n+\n+    private final AtomicBoolean unsubscribed = new AtomicBoolean();\n+\n+    @Override\n+    public final boolean isDisposed() {\n+        return unsubscribed.get();\n+    }\n+\n+    @Override\n+    public final void dispose() {\n+        if (unsubscribed.compareAndSet(false, true)) {\n+            if (Looper.myLooper() == Looper.getMainLooper()) {","path":"rxandroid/src/main/java/io/reactivex/android/MainThreadDisposable.java","position":72,"original_position":72,"commit_id":"6c52a4c60cac386e017bb023be6805cd416a0d4f","original_commit_id":"6c52a4c60cac386e017bb023be6805cd416a0d4f","user":{"login":"artem-zinnatullin","id":967132,"avatar_url":"https://avatars.githubusercontent.com/u/967132?v=3","gravatar_id":"","url":"https://api.github.com/users/artem-zinnatullin","html_url":"https://github.com/artem-zinnatullin","followers_url":"https://api.github.com/users/artem-zinnatullin/followers","following_url":"https://api.github.com/users/artem-zinnatullin/following{/other_user}","gists_url":"https://api.github.com/users/artem-zinnatullin/gists{/gist_id}","starred_url":"https://api.github.com/users/artem-zinnatullin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artem-zinnatullin/subscriptions","organizations_url":"https://api.github.com/users/artem-zinnatullin/orgs","repos_url":"https://api.github.com/users/artem-zinnatullin/repos","events_url":"https://api.github.com/users/artem-zinnatullin/events{/privacy}","received_events_url":"https://api.github.com/users/artem-zinnatullin/received_events","type":"User","site_admin":false},"body":"Ah, found this class in 1.x, so ok then looks like it works fine since RxBinding is huge user of it","created_at":"2016-08-06T09:51:08Z","updated_at":"2016-08-06T09:51:08Z","html_url":"https://github.com/ReactiveX/RxAndroid/pull/316#discussion_r73783840","pull_request_url":"https://api.github.com/repos/ReactiveX/RxAndroid/pulls/316","_links":{"self":{"href":"https://api.github.com/repos/ReactiveX/RxAndroid/pulls/comments/73783840"},"html":{"href":"https://github.com/ReactiveX/RxAndroid/pull/316#discussion_r73783840"},"pull_request":{"href":"https://api.github.com/repos/ReactiveX/RxAndroid/pulls/316"}}},"pull_request":{"url":"https://api.github.com/repos/ReactiveX/RxAndroid/pulls/316","id":80330880,"html_url":"https://github.com/ReactiveX/RxAndroid/pull/316","diff_url":"https://github.com/ReactiveX/RxAndroid/pull/316.diff","patch_url":"https://github.com/ReactiveX/RxAndroid/pull/316.patch","issue_url":"https://api.github.com/repos/ReactiveX/RxAndroid/issues/316","number":316,"state":"open","locked":false,"title":"Port library to RxJava 2.","user":{"login":"JakeWharton","id":66577,"avatar_url":"https://avatars.githubusercontent.com/u/66577?v=3","gravatar_id":"","url":"https://api.github.com/users/JakeWharton","html_url":"https://github.com/JakeWharton","followers_url":"https://api.github.com/users/JakeWharton/followers","following_url":"https://api.github.com/users/JakeWharton/following{/other_user}","gists_url":"https://api.github.com/users/JakeWharton/gists{/gist_id}","starred_url":"https://api.github.com/users/JakeWharton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JakeWharton/subscriptions","organizations_url":"https://api.github.com/users/JakeWharton/orgs","repos_url":"https://api.github.com/users/JakeWharton/repos","events_url":"https://api.github.com/users/JakeWharton/events{/privacy}","received_events_url":"https://api.github.com/users/JakeWharton/received_events","type":"User","site_admin":false},"body":"Closes #279. Closes #281.\r\n\r\n@dlew @akarnokd @artem-zinnatullin ","created_at":"2016-08-06T04:57:35Z","updated_at":"2016-08-06T09:51:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2dd652b7507f92cc4ac6f02d69727f724bab6172","assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/ReactiveX/RxAndroid/milestones/1","html_url":"https://github.com/ReactiveX/RxAndroid/milestones/RxJava%202.0","labels_url":"https://api.github.com/repos/ReactiveX/RxAndroid/milestones/1/labels","id":1740472,"number":1,"title":"RxJava 2.0","description":"","creator":{"login":"JakeWharton","id":66577,"avatar_url":"https://avatars.githubusercontent.com/u/66577?v=3","gravatar_id":"","url":"https://api.github.com/users/JakeWharton","html_url":"https://github.com/JakeWharton","followers_url":"https://api.github.com/users/JakeWharton/followers","following_url":"https://api.github.com/users/JakeWharton/following{/other_user}","gists_url":"https://api.github.com/users/JakeWharton/gists{/gist_id}","starred_url":"https://api.github.com/users/JakeWharton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JakeWharton/subscriptions","organizations_url":"https://api.github.com/users/JakeWharton/orgs","repos_url":"https://api.github.com/users/JakeWharton/repos","events_url":"https://api.github.com/users/JakeWharton/events{/privacy}","received_events_url":"https://api.github.com/users/JakeWharton/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":0,"state":"open","created_at":"2016-05-01T05:54:00Z","updated_at":"2016-08-06T04:57:36Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/ReactiveX/RxAndroid/pulls/316/commits","review_comments_url":"https://api.github.com/repos/ReactiveX/RxAndroid/pulls/316/comments","review_comment_url":"https://api.github.com/repos/ReactiveX/RxAndroid/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ReactiveX/RxAndroid/issues/316/comments","statuses_url":"https://api.github.com/repos/ReactiveX/RxAndroid/statuses/6c52a4c60cac386e017bb023be6805cd416a0d4f","head":{"label":"ReactiveX:jw/two","ref":"jw/two","sha":"6c52a4c60cac386e017bb023be6805cd416a0d4f","user":{"login":"ReactiveX","id":6407041,"avatar_url":"https://avatars.githubusercontent.com/u/6407041?v=3","gravatar_id":"","url":"https://api.github.com/users/ReactiveX","html_url":"https://github.com/ReactiveX","followers_url":"https://api.github.com/users/ReactiveX/followers","following_url":"https://api.github.com/users/ReactiveX/following{/other_user}","gists_url":"https://api.github.com/users/ReactiveX/gists{/gist_id}","starred_url":"https://api.github.com/users/ReactiveX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ReactiveX/subscriptions","organizations_url":"https://api.github.com/users/ReactiveX/orgs","repos_url":"https://api.github.com/users/ReactiveX/repos","events_url":"https://api.github.com/users/ReactiveX/events{/privacy}","received_events_url":"https://api.github.com/users/ReactiveX/received_events","type":"Organization","site_admin":false},"repo":{"id":23095954,"name":"RxAndroid","full_name":"ReactiveX/RxAndroid","owner":{"login":"ReactiveX","id":6407041,"avatar_url":"https://avatars.githubusercontent.com/u/6407041?v=3","gravatar_id":"","url":"https://api.github.com/users/ReactiveX","html_url":"https://github.com/ReactiveX","followers_url":"https://api.github.com/users/ReactiveX/followers","following_url":"https://api.github.com/users/ReactiveX/following{/other_user}","gists_url":"https://api.github.com/users/ReactiveX/gists{/gist_id}","starred_url":"https://api.github.com/users/ReactiveX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ReactiveX/subscriptions","organizations_url":"https://api.github.com/users/ReactiveX/orgs","repos_url":"https://api.github.com/users/ReactiveX/repos","events_url":"https://api.github.com/users/ReactiveX/events{/privacy}","received_events_url":"https://api.github.com/users/ReactiveX/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ReactiveX/RxAndroid","description":"RxJava bindings for Android","fork":false,"url":"https://api.github.com/repos/ReactiveX/RxAndroid","forks_url":"https://api.github.com/repos/ReactiveX/RxAndroid/forks","keys_url":"https://api.github.com/repos/ReactiveX/RxAndroid/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ReactiveX/RxAndroid/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ReactiveX/RxAndroid/teams","hooks_url":"https://api.github.com/repos/ReactiveX/RxAndroid/hooks","issue_events_url":"https://api.github.com/repos/ReactiveX/RxAndroid/issues/events{/number}","events_url":"https://api.github.com/repos/ReactiveX/RxAndroid/events","assignees_url":"https://api.github.com/repos/ReactiveX/RxAndroid/assignees{/user}","branches_url":"https://api.github.com/repos/ReactiveX/RxAndroid/branches{/branch}","tags_url":"https://api.github.com/repos/ReactiveX/RxAndroid/tags","blobs_url":"https://api.github.com/repos/ReactiveX/RxAndroid/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ReactiveX/RxAndroid/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ReactiveX/RxAndroid/git/refs{/sha}","trees_url":"https://api.github.com/repos/ReactiveX/RxAndroid/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ReactiveX/RxAndroid/statuses/{sha}","languages_url":"https://api.github.com/repos/ReactiveX/RxAndroid/languages","stargazers_url":"https://api.github.com/repos/ReactiveX/RxAndroid/stargazers","contributors_url":"https://api.github.com/repos/ReactiveX/RxAndroid/contributors","subscribers_url":"https://api.github.com/repos/ReactiveX/RxAndroid/subscribers","subscription_url":"https://api.github.com/repos/ReactiveX/RxAndroid/subscription","commits_url":"https://api.github.com/repos/ReactiveX/RxAndroid/commits{/sha}","git_commits_url":"https://api.github.com/repos/ReactiveX/RxAndroid/git/commits{/sha}","comments_url":"https://api.github.com/repos/ReactiveX/RxAndroid/comments{/number}","issue_comment_url":"https://api.github.com/repos/ReactiveX/RxAndroid/issues/comments{/number}","contents_url":"https://api.github.com/repos/ReactiveX/RxAndroid/contents/{+path}","compare_url":"https://api.github.com/repos/ReactiveX/RxAndroid/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ReactiveX/RxAndroid/merges","archive_url":"https://api.github.com/repos/ReactiveX/RxAndroid/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ReactiveX/RxAndroid/downloads","issues_url":"https://api.github.com/repos/ReactiveX/RxAndroid/issues{/number}","pulls_url":"https://api.github.com/repos/ReactiveX/RxAndroid/pulls{/number}","milestones_url":"https://api.github.com/repos/ReactiveX/RxAndroid/milestones{/number}","notifications_url":"https://api.github.com/repos/ReactiveX/RxAndroid/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ReactiveX/RxAndroid/labels{/name}","releases_url":"https://api.github.com/repos/ReactiveX/RxAndroid/releases{/id}","deployments_url":"https://api.github.com/repos/ReactiveX/RxAndroid/deployments","created_at":"2014-08-19T03:46:38Z","updated_at":"2016-08-06T09:29:31Z","pushed_at":"2016-08-06T05:04:58Z","git_url":"git://github.com/ReactiveX/RxAndroid.git","ssh_url":"git@github.com:ReactiveX/RxAndroid.git","clone_url":"https://github.com/ReactiveX/RxAndroid.git","svn_url":"https://github.com/ReactiveX/RxAndroid","homepage":"","size":1363,"stargazers_count":8113,"watchers_count":8113,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1448,"mirror_url":null,"open_issues_count":3,"forks":1448,"open_issues":3,"watchers":8113,"default_branch":"master"}},"base":{"label":"ReactiveX:2.x","ref":"2.x","sha":"477dd756816e1624b6000c664ea3a3318e2dabb6","user":{"login":"ReactiveX","id":6407041,"avatar_url":"https://avatars.githubusercontent.com/u/6407041?v=3","gravatar_id":"","url":"https://api.github.com/users/ReactiveX","html_url":"https://github.com/ReactiveX","followers_url":"https://api.github.com/users/ReactiveX/followers","following_url":"https://api.github.com/users/ReactiveX/following{/other_user}","gists_url":"https://api.github.com/users/ReactiveX/gists{/gist_id}","starred_url":"https://api.github.com/users/ReactiveX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ReactiveX/subscriptions","organizations_url":"https://api.github.com/users/ReactiveX/orgs","repos_url":"https://api.github.com/users/ReactiveX/repos","events_url":"https://api.github.com/users/ReactiveX/events{/privacy}","received_events_url":"https://api.github.com/users/ReactiveX/received_events","type":"Organization","site_admin":false},"repo":{"id":23095954,"name":"RxAndroid","full_name":"ReactiveX/RxAndroid","owner":{"login":"ReactiveX","id":6407041,"avatar_url":"https://avatars.githubusercontent.com/u/6407041?v=3","gravatar_id":"","url":"https://api.github.com/users/ReactiveX","html_url":"https://github.com/ReactiveX","followers_url":"https://api.github.com/users/ReactiveX/followers","following_url":"https://api.github.com/users/ReactiveX/following{/other_user}","gists_url":"https://api.github.com/users/ReactiveX/gists{/gist_id}","starred_url":"https://api.github.com/users/ReactiveX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ReactiveX/subscriptions","organizations_url":"https://api.github.com/users/ReactiveX/orgs","repos_url":"https://api.github.com/users/ReactiveX/repos","events_url":"https://api.github.com/users/ReactiveX/events{/privacy}","received_events_url":"https://api.github.com/users/ReactiveX/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ReactiveX/RxAndroid","description":"RxJava bindings for Android","fork":false,"url":"https://api.github.com/repos/ReactiveX/RxAndroid","forks_url":"https://api.github.com/repos/ReactiveX/RxAndroid/forks","keys_url":"https://api.github.com/repos/ReactiveX/RxAndroid/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ReactiveX/RxAndroid/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ReactiveX/RxAndroid/teams","hooks_url":"https://api.github.com/repos/ReactiveX/RxAndroid/hooks","issue_events_url":"https://api.github.com/repos/ReactiveX/RxAndroid/issues/events{/number}","events_url":"https://api.github.com/repos/ReactiveX/RxAndroid/events","assignees_url":"https://api.github.com/repos/ReactiveX/RxAndroid/assignees{/user}","branches_url":"https://api.github.com/repos/ReactiveX/RxAndroid/branches{/branch}","tags_url":"https://api.github.com/repos/ReactiveX/RxAndroid/tags","blobs_url":"https://api.github.com/repos/ReactiveX/RxAndroid/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ReactiveX/RxAndroid/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ReactiveX/RxAndroid/git/refs{/sha}","trees_url":"https://api.github.com/repos/ReactiveX/RxAndroid/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ReactiveX/RxAndroid/statuses/{sha}","languages_url":"https://api.github.com/repos/ReactiveX/RxAndroid/languages","stargazers_url":"https://api.github.com/repos/ReactiveX/RxAndroid/stargazers","contributors_url":"https://api.github.com/repos/ReactiveX/RxAndroid/contributors","subscribers_url":"https://api.github.com/repos/ReactiveX/RxAndroid/subscribers","subscription_url":"https://api.github.com/repos/ReactiveX/RxAndroid/subscription","commits_url":"https://api.github.com/repos/ReactiveX/RxAndroid/commits{/sha}","git_commits_url":"https://api.github.com/repos/ReactiveX/RxAndroid/git/commits{/sha}","comments_url":"https://api.github.com/repos/ReactiveX/RxAndroid/comments{/number}","issue_comment_url":"https://api.github.com/repos/ReactiveX/RxAndroid/issues/comments{/number}","contents_url":"https://api.github.com/repos/ReactiveX/RxAndroid/contents/{+path}","compare_url":"https://api.github.com/repos/ReactiveX/RxAndroid/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ReactiveX/RxAndroid/merges","archive_url":"https://api.github.com/repos/ReactiveX/RxAndroid/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ReactiveX/RxAndroid/downloads","issues_url":"https://api.github.com/repos/ReactiveX/RxAndroid/issues{/number}","pulls_url":"https://api.github.com/repos/ReactiveX/RxAndroid/pulls{/number}","milestones_url":"https://api.github.com/repos/ReactiveX/RxAndroid/milestones{/number}","notifications_url":"https://api.github.com/repos/ReactiveX/RxAndroid/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ReactiveX/RxAndroid/labels{/name}","releases_url":"https://api.github.com/repos/ReactiveX/RxAndroid/releases{/id}","deployments_url":"https://api.github.com/repos/ReactiveX/RxAndroid/deployments","created_at":"2014-08-19T03:46:38Z","updated_at":"2016-08-06T09:29:31Z","pushed_at":"2016-08-06T05:04:58Z","git_url":"git://github.com/ReactiveX/RxAndroid.git","ssh_url":"git@github.com:ReactiveX/RxAndroid.git","clone_url":"https://github.com/ReactiveX/RxAndroid.git","svn_url":"https://github.com/ReactiveX/RxAndroid","homepage":"","size":1363,"stargazers_count":8113,"watchers_count":8113,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1448,"mirror_url":null,"open_issues_count":3,"forks":1448,"open_issues":3,"watchers":8113,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ReactiveX/RxAndroid/pulls/316"},"html":{"href":"https://github.com/ReactiveX/RxAndroid/pull/316"},"issue":{"href":"https://api.github.com/repos/ReactiveX/RxAndroid/issues/316"},"comments":{"href":"https://api.github.com/repos/ReactiveX/RxAndroid/issues/316/comments"},"review_comments":{"href":"https://api.github.com/repos/ReactiveX/RxAndroid/pulls/316/comments"},"review_comment":{"href":"https://api.github.com/repos/ReactiveX/RxAndroid/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ReactiveX/RxAndroid/pulls/316/commits"},"statuses":{"href":"https://api.github.com/repos/ReactiveX/RxAndroid/statuses/6c52a4c60cac386e017bb023be6805cd416a0d4f"}}}}
{"actor":{"display_login":"artem-zinnatullin"}}