{"action":"created","comment":{"url":"https://api.github.com/repos/tessel/t2-firmware/pulls/comments/38706835","id":38706835,"diff_hunk":"@@ -169,6 +230,15 @@ Tessel.Port = function(name, socketPath, board) {\n   // Array of {size, callback} used to dispatch replies\n   this.replyQueue = [];\n \n+  // When the push function is called\n+  this.replyQueue.push = function () {\n+    // Make sure this socket is referenced until the data is returned\n+    this.sock._ref();\n+\n+    // Push the data into the array\n+    return Array.prototype.push.apply(this,arguments);","path":"node/tessel-export.js","position":159,"original_position":159,"commit_id":"d77e2f139404b9526f9b66d126ca5078efa0709c","original_commit_id":"d77e2f139404b9526f9b66d126ca5078efa0709c","user":{"login":"rwaldron","id":27985,"avatar_url":"https://avatars.githubusercontent.com/u/27985?v=3","gravatar_id":"","url":"https://api.github.com/users/rwaldron","html_url":"https://github.com/rwaldron","followers_url":"https://api.github.com/users/rwaldron/followers","following_url":"https://api.github.com/users/rwaldron/following{/other_user}","gists_url":"https://api.github.com/users/rwaldron/gists{/gist_id}","starred_url":"https://api.github.com/users/rwaldron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rwaldron/subscriptions","organizations_url":"https://api.github.com/users/rwaldron/orgs","repos_url":"https://api.github.com/users/rwaldron/repos","events_url":"https://api.github.com/users/rwaldron/events{/privacy}","received_events_url":"https://api.github.com/users/rwaldron/received_events","type":"User","site_admin":false},"body":"`this` isn't an array, it's the `port` instance that was bound on the line immediately following. The result is that nothing gets pushed into `this.replyQueue`. Even if that's fixed, this approach also doesn't account for `this.replyQueue.shift()`. I recommend strictly avoiding the redefinition of built-in object's methods.\r\n\r\nAlternative: \r\n\r\n```js\r\nTessel.Port.prototype.enqueue = function(reply) {\r\n  this.ref();\r\n  this.replyQueue.push(reply);\r\n};\r\n\r\n\r\nTessel.Port.prototype.dequeue = function() {\r\n  this.unref();\r\n  return this.replyQueue.shift();\r\n};\r\n```\r\n\r\n- all calls to `this.replyQueue.push(...)` become `this.enqueue(...)`\r\n- all calls to `this.replyQueue.shift()` become `this.dequeue()`\r\n","created_at":"2015-09-03T23:04:57Z","updated_at":"2015-09-03T23:04:57Z","html_url":"https://github.com/tessel/t2-firmware/pull/93#discussion_r38706835","pull_request_url":"https://api.github.com/repos/tessel/t2-firmware/pulls/93","_links":{"self":{"href":"https://api.github.com/repos/tessel/t2-firmware/pulls/comments/38706835"},"html":{"href":"https://github.com/tessel/t2-firmware/pull/93#discussion_r38706835"},"pull_request":{"href":"https://api.github.com/repos/tessel/t2-firmware/pulls/93"}}},"pull_request":{"url":"https://api.github.com/repos/tessel/t2-firmware/pulls/93","id":43707552,"html_url":"https://github.com/tessel/t2-firmware/pull/93","diff_url":"https://github.com/tessel/t2-firmware/pull/93.diff","patch_url":"https://github.com/tessel/t2-firmware/pull/93.patch","issue_url":"https://api.github.com/repos/tessel/t2-firmware/issues/93","number":93,"state":"open","locked":false,"title":"[WIP] Derefs port socket when command queue is empty","user":{"login":"johnnyman727","id":432909,"avatar_url":"https://avatars.githubusercontent.com/u/432909?v=3","gravatar_id":"","url":"https://api.github.com/users/johnnyman727","html_url":"https://github.com/johnnyman727","followers_url":"https://api.github.com/users/johnnyman727/followers","following_url":"https://api.github.com/users/johnnyman727/following{/other_user}","gists_url":"https://api.github.com/users/johnnyman727/gists{/gist_id}","starred_url":"https://api.github.com/users/johnnyman727/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnnyman727/subscriptions","organizations_url":"https://api.github.com/users/johnnyman727/orgs","repos_url":"https://api.github.com/users/johnnyman727/repos","events_url":"https://api.github.com/users/johnnyman727/events{/privacy}","received_events_url":"https://api.github.com/users/johnnyman727/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-08-30T04:55:20Z","updated_at":"2015-09-03T23:04:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/tessel/t2-firmware/pulls/93/commits","review_comments_url":"https://api.github.com/repos/tessel/t2-firmware/pulls/93/comments","review_comment_url":"https://api.github.com/repos/tessel/t2-firmware/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tessel/t2-firmware/issues/93/comments","statuses_url":"https://api.github.com/repos/tessel/t2-firmware/statuses/d77e2f139404b9526f9b66d126ca5078efa0709c","head":{"label":"tessel:jon-proc-end","ref":"jon-proc-end","sha":"d77e2f139404b9526f9b66d126ca5078efa0709c","user":{"login":"tessel","id":5573563,"avatar_url":"https://avatars.githubusercontent.com/u/5573563?v=3","gravatar_id":"","url":"https://api.github.com/users/tessel","html_url":"https://github.com/tessel","followers_url":"https://api.github.com/users/tessel/followers","following_url":"https://api.github.com/users/tessel/following{/other_user}","gists_url":"https://api.github.com/users/tessel/gists{/gist_id}","starred_url":"https://api.github.com/users/tessel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tessel/subscriptions","organizations_url":"https://api.github.com/users/tessel/orgs","repos_url":"https://api.github.com/users/tessel/repos","events_url":"https://api.github.com/users/tessel/events{/privacy}","received_events_url":"https://api.github.com/users/tessel/received_events","type":"Organization","site_admin":false},"repo":{"id":29262099,"name":"t2-firmware","full_name":"tessel/t2-firmware","owner":{"login":"tessel","id":5573563,"avatar_url":"https://avatars.githubusercontent.com/u/5573563?v=3","gravatar_id":"","url":"https://api.github.com/users/tessel","html_url":"https://github.com/tessel","followers_url":"https://api.github.com/users/tessel/followers","following_url":"https://api.github.com/users/tessel/following{/other_user}","gists_url":"https://api.github.com/users/tessel/gists{/gist_id}","starred_url":"https://api.github.com/users/tessel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tessel/subscriptions","organizations_url":"https://api.github.com/users/tessel/orgs","repos_url":"https://api.github.com/users/tessel/repos","events_url":"https://api.github.com/users/tessel/events{/privacy}","received_events_url":"https://api.github.com/users/tessel/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tessel/t2-firmware","description":"Firmware for Tessel 2's SAMD21 coprocessor and related SoC code","fork":false,"url":"https://api.github.com/repos/tessel/t2-firmware","forks_url":"https://api.github.com/repos/tessel/t2-firmware/forks","keys_url":"https://api.github.com/repos/tessel/t2-firmware/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tessel/t2-firmware/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tessel/t2-firmware/teams","hooks_url":"https://api.github.com/repos/tessel/t2-firmware/hooks","issue_events_url":"https://api.github.com/repos/tessel/t2-firmware/issues/events{/number}","events_url":"https://api.github.com/repos/tessel/t2-firmware/events","assignees_url":"https://api.github.com/repos/tessel/t2-firmware/assignees{/user}","branches_url":"https://api.github.com/repos/tessel/t2-firmware/branches{/branch}","tags_url":"https://api.github.com/repos/tessel/t2-firmware/tags","blobs_url":"https://api.github.com/repos/tessel/t2-firmware/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tessel/t2-firmware/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tessel/t2-firmware/git/refs{/sha}","trees_url":"https://api.github.com/repos/tessel/t2-firmware/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tessel/t2-firmware/statuses/{sha}","languages_url":"https://api.github.com/repos/tessel/t2-firmware/languages","stargazers_url":"https://api.github.com/repos/tessel/t2-firmware/stargazers","contributors_url":"https://api.github.com/repos/tessel/t2-firmware/contributors","subscribers_url":"https://api.github.com/repos/tessel/t2-firmware/subscribers","subscription_url":"https://api.github.com/repos/tessel/t2-firmware/subscription","commits_url":"https://api.github.com/repos/tessel/t2-firmware/commits{/sha}","git_commits_url":"https://api.github.com/repos/tessel/t2-firmware/git/commits{/sha}","comments_url":"https://api.github.com/repos/tessel/t2-firmware/comments{/number}","issue_comment_url":"https://api.github.com/repos/tessel/t2-firmware/issues/comments{/number}","contents_url":"https://api.github.com/repos/tessel/t2-firmware/contents/{+path}","compare_url":"https://api.github.com/repos/tessel/t2-firmware/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tessel/t2-firmware/merges","archive_url":"https://api.github.com/repos/tessel/t2-firmware/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tessel/t2-firmware/downloads","issues_url":"https://api.github.com/repos/tessel/t2-firmware/issues{/number}","pulls_url":"https://api.github.com/repos/tessel/t2-firmware/pulls{/number}","milestones_url":"https://api.github.com/repos/tessel/t2-firmware/milestones{/number}","notifications_url":"https://api.github.com/repos/tessel/t2-firmware/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tessel/t2-firmware/labels{/name}","releases_url":"https://api.github.com/repos/tessel/t2-firmware/releases{/id}","created_at":"2015-01-14T19:38:00Z","updated_at":"2015-08-06T14:00:25Z","pushed_at":"2015-09-03T21:47:50Z","git_url":"git://github.com/tessel/t2-firmware.git","ssh_url":"git@github.com:tessel/t2-firmware.git","clone_url":"https://github.com/tessel/t2-firmware.git","svn_url":"https://github.com/tessel/t2-firmware","homepage":"","size":1258,"stargazers_count":15,"watchers_count":15,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":27,"forks":5,"open_issues":27,"watchers":15,"default_branch":"master"}},"base":{"label":"tessel:master","ref":"master","sha":"ebb1d82c40c6beae3a9de1b5287d46f546b515f6","user":{"login":"tessel","id":5573563,"avatar_url":"https://avatars.githubusercontent.com/u/5573563?v=3","gravatar_id":"","url":"https://api.github.com/users/tessel","html_url":"https://github.com/tessel","followers_url":"https://api.github.com/users/tessel/followers","following_url":"https://api.github.com/users/tessel/following{/other_user}","gists_url":"https://api.github.com/users/tessel/gists{/gist_id}","starred_url":"https://api.github.com/users/tessel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tessel/subscriptions","organizations_url":"https://api.github.com/users/tessel/orgs","repos_url":"https://api.github.com/users/tessel/repos","events_url":"https://api.github.com/users/tessel/events{/privacy}","received_events_url":"https://api.github.com/users/tessel/received_events","type":"Organization","site_admin":false},"repo":{"id":29262099,"name":"t2-firmware","full_name":"tessel/t2-firmware","owner":{"login":"tessel","id":5573563,"avatar_url":"https://avatars.githubusercontent.com/u/5573563?v=3","gravatar_id":"","url":"https://api.github.com/users/tessel","html_url":"https://github.com/tessel","followers_url":"https://api.github.com/users/tessel/followers","following_url":"https://api.github.com/users/tessel/following{/other_user}","gists_url":"https://api.github.com/users/tessel/gists{/gist_id}","starred_url":"https://api.github.com/users/tessel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tessel/subscriptions","organizations_url":"https://api.github.com/users/tessel/orgs","repos_url":"https://api.github.com/users/tessel/repos","events_url":"https://api.github.com/users/tessel/events{/privacy}","received_events_url":"https://api.github.com/users/tessel/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tessel/t2-firmware","description":"Firmware for Tessel 2's SAMD21 coprocessor and related SoC code","fork":false,"url":"https://api.github.com/repos/tessel/t2-firmware","forks_url":"https://api.github.com/repos/tessel/t2-firmware/forks","keys_url":"https://api.github.com/repos/tessel/t2-firmware/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tessel/t2-firmware/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tessel/t2-firmware/teams","hooks_url":"https://api.github.com/repos/tessel/t2-firmware/hooks","issue_events_url":"https://api.github.com/repos/tessel/t2-firmware/issues/events{/number}","events_url":"https://api.github.com/repos/tessel/t2-firmware/events","assignees_url":"https://api.github.com/repos/tessel/t2-firmware/assignees{/user}","branches_url":"https://api.github.com/repos/tessel/t2-firmware/branches{/branch}","tags_url":"https://api.github.com/repos/tessel/t2-firmware/tags","blobs_url":"https://api.github.com/repos/tessel/t2-firmware/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tessel/t2-firmware/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tessel/t2-firmware/git/refs{/sha}","trees_url":"https://api.github.com/repos/tessel/t2-firmware/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tessel/t2-firmware/statuses/{sha}","languages_url":"https://api.github.com/repos/tessel/t2-firmware/languages","stargazers_url":"https://api.github.com/repos/tessel/t2-firmware/stargazers","contributors_url":"https://api.github.com/repos/tessel/t2-firmware/contributors","subscribers_url":"https://api.github.com/repos/tessel/t2-firmware/subscribers","subscription_url":"https://api.github.com/repos/tessel/t2-firmware/subscription","commits_url":"https://api.github.com/repos/tessel/t2-firmware/commits{/sha}","git_commits_url":"https://api.github.com/repos/tessel/t2-firmware/git/commits{/sha}","comments_url":"https://api.github.com/repos/tessel/t2-firmware/comments{/number}","issue_comment_url":"https://api.github.com/repos/tessel/t2-firmware/issues/comments{/number}","contents_url":"https://api.github.com/repos/tessel/t2-firmware/contents/{+path}","compare_url":"https://api.github.com/repos/tessel/t2-firmware/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tessel/t2-firmware/merges","archive_url":"https://api.github.com/repos/tessel/t2-firmware/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tessel/t2-firmware/downloads","issues_url":"https://api.github.com/repos/tessel/t2-firmware/issues{/number}","pulls_url":"https://api.github.com/repos/tessel/t2-firmware/pulls{/number}","milestones_url":"https://api.github.com/repos/tessel/t2-firmware/milestones{/number}","notifications_url":"https://api.github.com/repos/tessel/t2-firmware/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tessel/t2-firmware/labels{/name}","releases_url":"https://api.github.com/repos/tessel/t2-firmware/releases{/id}","created_at":"2015-01-14T19:38:00Z","updated_at":"2015-08-06T14:00:25Z","pushed_at":"2015-09-03T21:47:50Z","git_url":"git://github.com/tessel/t2-firmware.git","ssh_url":"git@github.com:tessel/t2-firmware.git","clone_url":"https://github.com/tessel/t2-firmware.git","svn_url":"https://github.com/tessel/t2-firmware","homepage":"","size":1258,"stargazers_count":15,"watchers_count":15,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":27,"forks":5,"open_issues":27,"watchers":15,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tessel/t2-firmware/pulls/93"},"html":{"href":"https://github.com/tessel/t2-firmware/pull/93"},"issue":{"href":"https://api.github.com/repos/tessel/t2-firmware/issues/93"},"comments":{"href":"https://api.github.com/repos/tessel/t2-firmware/issues/93/comments"},"review_comments":{"href":"https://api.github.com/repos/tessel/t2-firmware/pulls/93/comments"},"review_comment":{"href":"https://api.github.com/repos/tessel/t2-firmware/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tessel/t2-firmware/pulls/93/commits"},"statuses":{"href":"https://api.github.com/repos/tessel/t2-firmware/statuses/d77e2f139404b9526f9b66d126ca5078efa0709c"}}}}