{"action":"created","comment":{"url":"https://api.github.com/repos/santigimeno/node-pcsclite/pulls/comments/40942653","id":40942653,"diff_hunk":"@@ -379,33 +383,32 @@ void CardReader::HandlerFunction(void* arg) {\n     card_reader_state.szReader = reader->m_name.c_str();\n     card_reader_state.dwCurrentState = SCARD_STATE_UNAWARE;\n \n-    bool keep_watching(result == SCARD_S_SUCCESS);\n-    while (keep_watching) {\n-\n+    while (!reader->m_state) {\n         result = SCardGetStatusChange(reader->m_status_card_context, INFINITE, &card_reader_state, 1);\n-        keep_watching = (result == SCARD_S_SUCCESS) && (!reader->m_state);\n \n         uv_mutex_lock(&reader->m_mutex);\n         if (reader->m_state == 1) {\n+            // Exit requested by user. Notify close method about SCardStatusChange was interrupted.\n             uv_cond_signal(&reader->m_cond);\n-        }\n-\n-        if (!keep_watching) {\n+            async_baton->async_result->do_exit = true;\n+        } else if (result != (LONG)SCARD_S_SUCCESS) {\n+            // Exit this loop due to errors","path":"src/cardreader.cpp","position":72,"original_position":72,"commit_id":"fe3a12d4da29b091ae4c4d6bf62ebbf2cfbd268b","original_commit_id":"fe3a12d4da29b091ae4c4d6bf62ebbf2cfbd268b","user":{"login":"santigimeno","id":1084056,"avatar_url":"https://avatars.githubusercontent.com/u/1084056?v=3","gravatar_id":"","url":"https://api.github.com/users/santigimeno","html_url":"https://github.com/santigimeno","followers_url":"https://api.github.com/users/santigimeno/followers","following_url":"https://api.github.com/users/santigimeno/following{/other_user}","gists_url":"https://api.github.com/users/santigimeno/gists{/gist_id}","starred_url":"https://api.github.com/users/santigimeno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/santigimeno/subscriptions","organizations_url":"https://api.github.com/users/santigimeno/orgs","repos_url":"https://api.github.com/users/santigimeno/repos","events_url":"https://api.github.com/users/santigimeno/events{/privacy}","received_events_url":"https://api.github.com/users/santigimeno/received_events","type":"User","site_admin":false},"body":"You could do:\r\n```\r\nasync_baton->async_result->do_exit = (reader->m_state != 0);\r\n```\r\nonce after the ifs","created_at":"2015-10-01T17:39:30Z","updated_at":"2015-10-01T17:39:30Z","html_url":"https://github.com/santigimeno/node-pcsclite/pull/46#discussion_r40942653","pull_request_url":"https://api.github.com/repos/santigimeno/node-pcsclite/pulls/46","_links":{"self":{"href":"https://api.github.com/repos/santigimeno/node-pcsclite/pulls/comments/40942653"},"html":{"href":"https://github.com/santigimeno/node-pcsclite/pull/46#discussion_r40942653"},"pull_request":{"href":"https://api.github.com/repos/santigimeno/node-pcsclite/pulls/46"}}},"pull_request":{"url":"https://api.github.com/repos/santigimeno/node-pcsclite/pulls/46","id":45907425,"html_url":"https://github.com/santigimeno/node-pcsclite/pull/46","diff_url":"https://github.com/santigimeno/node-pcsclite/pull/46.diff","patch_url":"https://github.com/santigimeno/node-pcsclite/pull/46.patch","issue_url":"https://api.github.com/repos/santigimeno/node-pcsclite/issues/46","number":46,"state":"open","locked":false,"title":"Handle last event before exit","user":{"login":"framillien","id":5042752,"avatar_url":"https://avatars.githubusercontent.com/u/5042752?v=3","gravatar_id":"","url":"https://api.github.com/users/framillien","html_url":"https://github.com/framillien","followers_url":"https://api.github.com/users/framillien/followers","following_url":"https://api.github.com/users/framillien/following{/other_user}","gists_url":"https://api.github.com/users/framillien/gists{/gist_id}","starred_url":"https://api.github.com/users/framillien/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/framillien/subscriptions","organizations_url":"https://api.github.com/users/framillien/orgs","repos_url":"https://api.github.com/users/framillien/repos","events_url":"https://api.github.com/users/framillien/events{/privacy}","received_events_url":"https://api.github.com/users/framillien/received_events","type":"User","site_admin":false},"body":"Always send last event (if any) before handling exit.","created_at":"2015-09-24T14:57:46Z","updated_at":"2015-10-01T17:39:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"45863319092573b9ec385ffbd3e6a54c53ae3f99","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/santigimeno/node-pcsclite/pulls/46/commits","review_comments_url":"https://api.github.com/repos/santigimeno/node-pcsclite/pulls/46/comments","review_comment_url":"https://api.github.com/repos/santigimeno/node-pcsclite/pulls/comments{/number}","comments_url":"https://api.github.com/repos/santigimeno/node-pcsclite/issues/46/comments","statuses_url":"https://api.github.com/repos/santigimeno/node-pcsclite/statuses/fe3a12d4da29b091ae4c4d6bf62ebbf2cfbd268b","head":{"label":"framillien:fix_last_event","ref":"fix_last_event","sha":"fe3a12d4da29b091ae4c4d6bf62ebbf2cfbd268b","user":{"login":"framillien","id":5042752,"avatar_url":"https://avatars.githubusercontent.com/u/5042752?v=3","gravatar_id":"","url":"https://api.github.com/users/framillien","html_url":"https://github.com/framillien","followers_url":"https://api.github.com/users/framillien/followers","following_url":"https://api.github.com/users/framillien/following{/other_user}","gists_url":"https://api.github.com/users/framillien/gists{/gist_id}","starred_url":"https://api.github.com/users/framillien/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/framillien/subscriptions","organizations_url":"https://api.github.com/users/framillien/orgs","repos_url":"https://api.github.com/users/framillien/repos","events_url":"https://api.github.com/users/framillien/events{/privacy}","received_events_url":"https://api.github.com/users/framillien/received_events","type":"User","site_admin":false},"repo":{"id":41545665,"name":"node-pcsclite","full_name":"framillien/node-pcsclite","owner":{"login":"framillien","id":5042752,"avatar_url":"https://avatars.githubusercontent.com/u/5042752?v=3","gravatar_id":"","url":"https://api.github.com/users/framillien","html_url":"https://github.com/framillien","followers_url":"https://api.github.com/users/framillien/followers","following_url":"https://api.github.com/users/framillien/following{/other_user}","gists_url":"https://api.github.com/users/framillien/gists{/gist_id}","starred_url":"https://api.github.com/users/framillien/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/framillien/subscriptions","organizations_url":"https://api.github.com/users/framillien/orgs","repos_url":"https://api.github.com/users/framillien/repos","events_url":"https://api.github.com/users/framillien/events{/privacy}","received_events_url":"https://api.github.com/users/framillien/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/framillien/node-pcsclite","description":"Bindings over pcsclite to access Smart Cards","fork":true,"url":"https://api.github.com/repos/framillien/node-pcsclite","forks_url":"https://api.github.com/repos/framillien/node-pcsclite/forks","keys_url":"https://api.github.com/repos/framillien/node-pcsclite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/framillien/node-pcsclite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/framillien/node-pcsclite/teams","hooks_url":"https://api.github.com/repos/framillien/node-pcsclite/hooks","issue_events_url":"https://api.github.com/repos/framillien/node-pcsclite/issues/events{/number}","events_url":"https://api.github.com/repos/framillien/node-pcsclite/events","assignees_url":"https://api.github.com/repos/framillien/node-pcsclite/assignees{/user}","branches_url":"https://api.github.com/repos/framillien/node-pcsclite/branches{/branch}","tags_url":"https://api.github.com/repos/framillien/node-pcsclite/tags","blobs_url":"https://api.github.com/repos/framillien/node-pcsclite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/framillien/node-pcsclite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/framillien/node-pcsclite/git/refs{/sha}","trees_url":"https://api.github.com/repos/framillien/node-pcsclite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/framillien/node-pcsclite/statuses/{sha}","languages_url":"https://api.github.com/repos/framillien/node-pcsclite/languages","stargazers_url":"https://api.github.com/repos/framillien/node-pcsclite/stargazers","contributors_url":"https://api.github.com/repos/framillien/node-pcsclite/contributors","subscribers_url":"https://api.github.com/repos/framillien/node-pcsclite/subscribers","subscription_url":"https://api.github.com/repos/framillien/node-pcsclite/subscription","commits_url":"https://api.github.com/repos/framillien/node-pcsclite/commits{/sha}","git_commits_url":"https://api.github.com/repos/framillien/node-pcsclite/git/commits{/sha}","comments_url":"https://api.github.com/repos/framillien/node-pcsclite/comments{/number}","issue_comment_url":"https://api.github.com/repos/framillien/node-pcsclite/issues/comments{/number}","contents_url":"https://api.github.com/repos/framillien/node-pcsclite/contents/{+path}","compare_url":"https://api.github.com/repos/framillien/node-pcsclite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/framillien/node-pcsclite/merges","archive_url":"https://api.github.com/repos/framillien/node-pcsclite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/framillien/node-pcsclite/downloads","issues_url":"https://api.github.com/repos/framillien/node-pcsclite/issues{/number}","pulls_url":"https://api.github.com/repos/framillien/node-pcsclite/pulls{/number}","milestones_url":"https://api.github.com/repos/framillien/node-pcsclite/milestones{/number}","notifications_url":"https://api.github.com/repos/framillien/node-pcsclite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/framillien/node-pcsclite/labels{/name}","releases_url":"https://api.github.com/repos/framillien/node-pcsclite/releases{/id}","created_at":"2015-08-28T12:14:43Z","updated_at":"2015-08-28T12:14:43Z","pushed_at":"2015-10-01T14:29:50Z","git_url":"git://github.com/framillien/node-pcsclite.git","ssh_url":"git@github.com:framillien/node-pcsclite.git","clone_url":"https://github.com/framillien/node-pcsclite.git","svn_url":"https://github.com/framillien/node-pcsclite","homepage":null,"size":251,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"santigimeno:fix_locks","ref":"fix_locks","sha":"770f921217f0bcb40fd702e5f53c6e8b5af54d09","user":{"login":"santigimeno","id":1084056,"avatar_url":"https://avatars.githubusercontent.com/u/1084056?v=3","gravatar_id":"","url":"https://api.github.com/users/santigimeno","html_url":"https://github.com/santigimeno","followers_url":"https://api.github.com/users/santigimeno/followers","following_url":"https://api.github.com/users/santigimeno/following{/other_user}","gists_url":"https://api.github.com/users/santigimeno/gists{/gist_id}","starred_url":"https://api.github.com/users/santigimeno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/santigimeno/subscriptions","organizations_url":"https://api.github.com/users/santigimeno/orgs","repos_url":"https://api.github.com/users/santigimeno/repos","events_url":"https://api.github.com/users/santigimeno/events{/privacy}","received_events_url":"https://api.github.com/users/santigimeno/received_events","type":"User","site_admin":false},"repo":{"id":10817553,"name":"node-pcsclite","full_name":"santigimeno/node-pcsclite","owner":{"login":"santigimeno","id":1084056,"avatar_url":"https://avatars.githubusercontent.com/u/1084056?v=3","gravatar_id":"","url":"https://api.github.com/users/santigimeno","html_url":"https://github.com/santigimeno","followers_url":"https://api.github.com/users/santigimeno/followers","following_url":"https://api.github.com/users/santigimeno/following{/other_user}","gists_url":"https://api.github.com/users/santigimeno/gists{/gist_id}","starred_url":"https://api.github.com/users/santigimeno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/santigimeno/subscriptions","organizations_url":"https://api.github.com/users/santigimeno/orgs","repos_url":"https://api.github.com/users/santigimeno/repos","events_url":"https://api.github.com/users/santigimeno/events{/privacy}","received_events_url":"https://api.github.com/users/santigimeno/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/santigimeno/node-pcsclite","description":"Bindings over pcsclite to access Smart Cards","fork":false,"url":"https://api.github.com/repos/santigimeno/node-pcsclite","forks_url":"https://api.github.com/repos/santigimeno/node-pcsclite/forks","keys_url":"https://api.github.com/repos/santigimeno/node-pcsclite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/santigimeno/node-pcsclite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/santigimeno/node-pcsclite/teams","hooks_url":"https://api.github.com/repos/santigimeno/node-pcsclite/hooks","issue_events_url":"https://api.github.com/repos/santigimeno/node-pcsclite/issues/events{/number}","events_url":"https://api.github.com/repos/santigimeno/node-pcsclite/events","assignees_url":"https://api.github.com/repos/santigimeno/node-pcsclite/assignees{/user}","branches_url":"https://api.github.com/repos/santigimeno/node-pcsclite/branches{/branch}","tags_url":"https://api.github.com/repos/santigimeno/node-pcsclite/tags","blobs_url":"https://api.github.com/repos/santigimeno/node-pcsclite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/santigimeno/node-pcsclite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/santigimeno/node-pcsclite/git/refs{/sha}","trees_url":"https://api.github.com/repos/santigimeno/node-pcsclite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/santigimeno/node-pcsclite/statuses/{sha}","languages_url":"https://api.github.com/repos/santigimeno/node-pcsclite/languages","stargazers_url":"https://api.github.com/repos/santigimeno/node-pcsclite/stargazers","contributors_url":"https://api.github.com/repos/santigimeno/node-pcsclite/contributors","subscribers_url":"https://api.github.com/repos/santigimeno/node-pcsclite/subscribers","subscription_url":"https://api.github.com/repos/santigimeno/node-pcsclite/subscription","commits_url":"https://api.github.com/repos/santigimeno/node-pcsclite/commits{/sha}","git_commits_url":"https://api.github.com/repos/santigimeno/node-pcsclite/git/commits{/sha}","comments_url":"https://api.github.com/repos/santigimeno/node-pcsclite/comments{/number}","issue_comment_url":"https://api.github.com/repos/santigimeno/node-pcsclite/issues/comments{/number}","contents_url":"https://api.github.com/repos/santigimeno/node-pcsclite/contents/{+path}","compare_url":"https://api.github.com/repos/santigimeno/node-pcsclite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/santigimeno/node-pcsclite/merges","archive_url":"https://api.github.com/repos/santigimeno/node-pcsclite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/santigimeno/node-pcsclite/downloads","issues_url":"https://api.github.com/repos/santigimeno/node-pcsclite/issues{/number}","pulls_url":"https://api.github.com/repos/santigimeno/node-pcsclite/pulls{/number}","milestones_url":"https://api.github.com/repos/santigimeno/node-pcsclite/milestones{/number}","notifications_url":"https://api.github.com/repos/santigimeno/node-pcsclite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/santigimeno/node-pcsclite/labels{/name}","releases_url":"https://api.github.com/repos/santigimeno/node-pcsclite/releases{/id}","created_at":"2013-06-20T10:29:56Z","updated_at":"2015-10-01T12:01:40Z","pushed_at":"2015-10-01T12:20:16Z","git_url":"git://github.com/santigimeno/node-pcsclite.git","ssh_url":"git@github.com:santigimeno/node-pcsclite.git","clone_url":"https://github.com/santigimeno/node-pcsclite.git","svn_url":"https://github.com/santigimeno/node-pcsclite","homepage":null,"size":655,"stargazers_count":23,"watchers_count":23,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":8,"forks":15,"open_issues":8,"watchers":23,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/santigimeno/node-pcsclite/pulls/46"},"html":{"href":"https://github.com/santigimeno/node-pcsclite/pull/46"},"issue":{"href":"https://api.github.com/repos/santigimeno/node-pcsclite/issues/46"},"comments":{"href":"https://api.github.com/repos/santigimeno/node-pcsclite/issues/46/comments"},"review_comments":{"href":"https://api.github.com/repos/santigimeno/node-pcsclite/pulls/46/comments"},"review_comment":{"href":"https://api.github.com/repos/santigimeno/node-pcsclite/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/santigimeno/node-pcsclite/pulls/46/commits"},"statuses":{"href":"https://api.github.com/repos/santigimeno/node-pcsclite/statuses/fe3a12d4da29b091ae4c4d6bf62ebbf2cfbd268b"}}}}