{"action":"created","comment":{"url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/pulls/comments/154941252","pull_request_review_id":81177915,"id":154941252,"diff_hunk":"@@ -0,0 +1,68 @@\n+package kin.sdk.core;\n+\n+\n+import android.os.Handler;\n+import android.os.Looper;\n+import java.util.concurrent.Callable;\n+import java.util.concurrent.ExecutorService;\n+import java.util.concurrent.Executors;\n+import java.util.concurrent.Future;\n+\n+public class Request<T> {\n+\n+    private static final ExecutorService executorService = Executors.newCachedThreadPool();\n+    private final Handler mainHandler;\n+    private final Callable<T> callable;\n+    private boolean cancelled;\n+    private boolean executed;\n+    private Future<?> future;\n+    private ResultCallback<T> resultCallback;\n+\n+    Request(Callable<T> callable) {\n+        this.callable = callable;\n+        this.mainHandler = new Handler(Looper.getMainLooper());\n+    }\n+\n+    synchronized public void run(ResultCallback<T> callback) {\n+        if (callback == null) {\n+            throw new IllegalArgumentException(\"callback cannot be null.\");\n+        }\n+        if (executed) {\n+            throw new IllegalStateException(\"Request already running.\");\n+        }\n+        if (cancelled) {\n+            throw new IllegalStateException(\"Request already cancelled.\");\n+        }\n+        executed = true;\n+        submitFuture(callable, callback);\n+    }\n+\n+    private void submitFuture(final Callable<T> callable, ResultCallback<T> callback) {\n+        this.resultCallback = callback;\n+        future = executorService.submit(() -> {\n+            try {\n+                final T result = callable.call();\n+                executeOnMainThreadIfNotInterrupted(() -> resultCallback.onResult(result));\n+            } catch (final Exception e) {\n+                executeOnMainThreadIfNotInterrupted(() -> resultCallback.onError(e));\n+            }\n+        });\n+    }\n+\n+    private synchronized void executeOnMainThreadIfNotInterrupted(Runnable runnable) {\n+        if (!cancelled) {\n+            mainHandler.post(runnable);\n+        }\n+    }\n+\n+    synchronized public void cancel() {","path":"kin-sdk-core/src/main/java/kin/sdk/core/Request.java","position":67,"original_position":58,"commit_id":"f69ff055adf986f290caecea3ee5b906e0c20b9a","original_commit_id":"b0894f2fb60417692e598374a4ff722e8785dfda","user":{"login":"OrenZak","id":8303735,"avatar_url":"https://avatars2.githubusercontent.com/u/8303735?v=4","gravatar_id":"","url":"https://api.github.com/users/OrenZak","html_url":"https://github.com/OrenZak","followers_url":"https://api.github.com/users/OrenZak/followers","following_url":"https://api.github.com/users/OrenZak/following{/other_user}","gists_url":"https://api.github.com/users/OrenZak/gists{/gist_id}","starred_url":"https://api.github.com/users/OrenZak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OrenZak/subscriptions","organizations_url":"https://api.github.com/users/OrenZak/orgs","repos_url":"https://api.github.com/users/OrenZak/repos","events_url":"https://api.github.com/users/OrenZak/events{/privacy}","received_events_url":"https://api.github.com/users/OrenZak/received_events","type":"User","site_admin":false},"body":"👍 ","created_at":"2017-12-05T13:18:52Z","updated_at":"2017-12-05T13:18:53Z","html_url":"https://github.com/kinfoundation/kin-sdk-core-android/pull/69#discussion_r154941252","pull_request_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/pulls/69","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/pulls/comments/154941252"},"html":{"href":"https://github.com/kinfoundation/kin-sdk-core-android/pull/69#discussion_r154941252"},"pull_request":{"href":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/pulls/69"}},"in_reply_to_id":154915303},"pull_request":{"url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/pulls/69","id":156422270,"html_url":"https://github.com/kinfoundation/kin-sdk-core-android/pull/69","diff_url":"https://github.com/kinfoundation/kin-sdk-core-android/pull/69.diff","patch_url":"https://github.com/kinfoundation/kin-sdk-core-android/pull/69.patch","issue_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/issues/69","number":69,"state":"open","locked":false,"title":"KIK-7927 - Add cancelation to async","user":{"login":"yosriz","id":1626032,"avatar_url":"https://avatars3.githubusercontent.com/u/1626032?v=4","gravatar_id":"","url":"https://api.github.com/users/yosriz","html_url":"https://github.com/yosriz","followers_url":"https://api.github.com/users/yosriz/followers","following_url":"https://api.github.com/users/yosriz/following{/other_user}","gists_url":"https://api.github.com/users/yosriz/gists{/gist_id}","starred_url":"https://api.github.com/users/yosriz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yosriz/subscriptions","organizations_url":"https://api.github.com/users/yosriz/orgs","repos_url":"https://api.github.com/users/yosriz/repos","events_url":"https://api.github.com/users/yosriz/events{/privacy}","received_events_url":"https://api.github.com/users/yosriz/received_events","type":"User","site_admin":false},"body":"* initial suggestion, wrap each operation with Request class, that\r\n includes cancellation\r\n* refactor sample app to use new approach\r\n\r\nTBD - add additional tests (RequestTest)","created_at":"2017-12-05T10:20:26Z","updated_at":"2017-12-05T13:18:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2ddf6b81f1b1393f949cc6095e88472304634cb5","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/pulls/69/commits","review_comments_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/pulls/69/comments","review_comment_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/issues/69/comments","statuses_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/statuses/f69ff055adf986f290caecea3ee5b906e0c20b9a","head":{"label":"kinfoundation:KIK-7927-Add-cancelation-to-async","ref":"KIK-7927-Add-cancelation-to-async","sha":"f69ff055adf986f290caecea3ee5b906e0c20b9a","user":{"login":"kinfoundation","id":28860603,"avatar_url":"https://avatars2.githubusercontent.com/u/28860603?v=4","gravatar_id":"","url":"https://api.github.com/users/kinfoundation","html_url":"https://github.com/kinfoundation","followers_url":"https://api.github.com/users/kinfoundation/followers","following_url":"https://api.github.com/users/kinfoundation/following{/other_user}","gists_url":"https://api.github.com/users/kinfoundation/gists{/gist_id}","starred_url":"https://api.github.com/users/kinfoundation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kinfoundation/subscriptions","organizations_url":"https://api.github.com/users/kinfoundation/orgs","repos_url":"https://api.github.com/users/kinfoundation/repos","events_url":"https://api.github.com/users/kinfoundation/events{/privacy}","received_events_url":"https://api.github.com/users/kinfoundation/received_events","type":"Organization","site_admin":false},"repo":{"id":108967562,"name":"kin-sdk-core-android","full_name":"kinfoundation/kin-sdk-core-android","owner":{"login":"kinfoundation","id":28860603,"avatar_url":"https://avatars2.githubusercontent.com/u/28860603?v=4","gravatar_id":"","url":"https://api.github.com/users/kinfoundation","html_url":"https://github.com/kinfoundation","followers_url":"https://api.github.com/users/kinfoundation/followers","following_url":"https://api.github.com/users/kinfoundation/following{/other_user}","gists_url":"https://api.github.com/users/kinfoundation/gists{/gist_id}","starred_url":"https://api.github.com/users/kinfoundation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kinfoundation/subscriptions","organizations_url":"https://api.github.com/users/kinfoundation/orgs","repos_url":"https://api.github.com/users/kinfoundation/repos","events_url":"https://api.github.com/users/kinfoundation/events{/privacy}","received_events_url":"https://api.github.com/users/kinfoundation/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kinfoundation/kin-sdk-core-android","description":"Android library responsible for creating a new Ethereum account and managing KIN balance and transactions.","fork":false,"url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android","forks_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/forks","keys_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/teams","hooks_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/hooks","issue_events_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/issues/events{/number}","events_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/events","assignees_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/assignees{/user}","branches_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/branches{/branch}","tags_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/tags","blobs_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/git/refs{/sha}","trees_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/statuses/{sha}","languages_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/languages","stargazers_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/stargazers","contributors_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/contributors","subscribers_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/subscribers","subscription_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/subscription","commits_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/commits{/sha}","git_commits_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/git/commits{/sha}","comments_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/comments{/number}","issue_comment_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/issues/comments{/number}","contents_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/contents/{+path}","compare_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/merges","archive_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/downloads","issues_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/issues{/number}","pulls_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/pulls{/number}","milestones_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/milestones{/number}","notifications_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/labels{/name}","releases_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/releases{/id}","deployments_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/deployments","created_at":"2017-10-31T08:37:19Z","updated_at":"2017-11-29T18:15:53Z","pushed_at":"2017-12-05T12:31:40Z","git_url":"git://github.com/kinfoundation/kin-sdk-core-android.git","ssh_url":"git@github.com:kinfoundation/kin-sdk-core-android.git","clone_url":"https://github.com/kinfoundation/kin-sdk-core-android.git","svn_url":"https://github.com/kinfoundation/kin-sdk-core-android","homepage":"","size":87977,"stargazers_count":6,"watchers_count":6,"language":"Java","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":3,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":3,"watchers":6,"default_branch":"dev"}},"base":{"label":"kinfoundation:dev","ref":"dev","sha":"2feaefe7e028c3362ac7a4dd126d9ebc2514f346","user":{"login":"kinfoundation","id":28860603,"avatar_url":"https://avatars2.githubusercontent.com/u/28860603?v=4","gravatar_id":"","url":"https://api.github.com/users/kinfoundation","html_url":"https://github.com/kinfoundation","followers_url":"https://api.github.com/users/kinfoundation/followers","following_url":"https://api.github.com/users/kinfoundation/following{/other_user}","gists_url":"https://api.github.com/users/kinfoundation/gists{/gist_id}","starred_url":"https://api.github.com/users/kinfoundation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kinfoundation/subscriptions","organizations_url":"https://api.github.com/users/kinfoundation/orgs","repos_url":"https://api.github.com/users/kinfoundation/repos","events_url":"https://api.github.com/users/kinfoundation/events{/privacy}","received_events_url":"https://api.github.com/users/kinfoundation/received_events","type":"Organization","site_admin":false},"repo":{"id":108967562,"name":"kin-sdk-core-android","full_name":"kinfoundation/kin-sdk-core-android","owner":{"login":"kinfoundation","id":28860603,"avatar_url":"https://avatars2.githubusercontent.com/u/28860603?v=4","gravatar_id":"","url":"https://api.github.com/users/kinfoundation","html_url":"https://github.com/kinfoundation","followers_url":"https://api.github.com/users/kinfoundation/followers","following_url":"https://api.github.com/users/kinfoundation/following{/other_user}","gists_url":"https://api.github.com/users/kinfoundation/gists{/gist_id}","starred_url":"https://api.github.com/users/kinfoundation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kinfoundation/subscriptions","organizations_url":"https://api.github.com/users/kinfoundation/orgs","repos_url":"https://api.github.com/users/kinfoundation/repos","events_url":"https://api.github.com/users/kinfoundation/events{/privacy}","received_events_url":"https://api.github.com/users/kinfoundation/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kinfoundation/kin-sdk-core-android","description":"Android library responsible for creating a new Ethereum account and managing KIN balance and transactions.","fork":false,"url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android","forks_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/forks","keys_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/teams","hooks_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/hooks","issue_events_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/issues/events{/number}","events_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/events","assignees_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/assignees{/user}","branches_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/branches{/branch}","tags_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/tags","blobs_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/git/refs{/sha}","trees_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/statuses/{sha}","languages_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/languages","stargazers_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/stargazers","contributors_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/contributors","subscribers_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/subscribers","subscription_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/subscription","commits_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/commits{/sha}","git_commits_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/git/commits{/sha}","comments_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/comments{/number}","issue_comment_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/issues/comments{/number}","contents_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/contents/{+path}","compare_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/merges","archive_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/downloads","issues_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/issues{/number}","pulls_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/pulls{/number}","milestones_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/milestones{/number}","notifications_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/labels{/name}","releases_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/releases{/id}","deployments_url":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/deployments","created_at":"2017-10-31T08:37:19Z","updated_at":"2017-11-29T18:15:53Z","pushed_at":"2017-12-05T12:31:40Z","git_url":"git://github.com/kinfoundation/kin-sdk-core-android.git","ssh_url":"git@github.com:kinfoundation/kin-sdk-core-android.git","clone_url":"https://github.com/kinfoundation/kin-sdk-core-android.git","svn_url":"https://github.com/kinfoundation/kin-sdk-core-android","homepage":"","size":87977,"stargazers_count":6,"watchers_count":6,"language":"Java","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":3,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":3,"watchers":6,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/pulls/69"},"html":{"href":"https://github.com/kinfoundation/kin-sdk-core-android/pull/69"},"issue":{"href":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/issues/69"},"comments":{"href":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/issues/69/comments"},"review_comments":{"href":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/pulls/69/comments"},"review_comment":{"href":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/pulls/69/commits"},"statuses":{"href":"https://api.github.com/repos/kinfoundation/kin-sdk-core-android/statuses/f69ff055adf986f290caecea3ee5b906e0c20b9a"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"OrenZak"}}