{"action":"created","comment":{"url":"https://api.github.com/repos/nodejs/node/pulls/comments/113975635","pull_request_review_id":35411329,"id":113975635,"diff_hunk":"@@ -1057,3 +1057,75 @@ exports._exceptionWithHostPort = function(err,\n // process.versions needs a custom function as some values are lazy-evaluated.\n process.versions[exports.inspect.custom] =\n   (depth) => exports.format(JSON.parse(JSON.stringify(process.versions)));\n+\n+\n+/**\n+ * @typedef {Object} callbackifyOptions\n+ * @property {function} transformer\n+ * @property {boolean} toSplat\n+ * @property {Array.<String>} project\n+ */\n+\n+/**\n+ * @param {function(): Promise} orig\n+ * @param {callbackifyOptions} options\n+ */\n+function callbackify(orig, options) {\n+  if (typeof orig !== 'function') {\n+    throw new TypeError('The first argument to callbackify() ' +\n+                        'must be a function');\n+  }\n+\n+  // we have two way to convert the returned value into multiple arguments\n+  // either splat it or project some of it's keys\n+  if ('toSplat' in options && 'project' in options)\n+    throw new TypeError('callbackify options can specify either ' +\n+                        '`toSplat` or `project`, but not both');\n+  const toSplat = options.toSplat;\n+  const project = options.project;\n+\n+  const fn = function(...args) {\n+    const cb = args.pop();\n+    if (typeof cb !== 'function') {\n+      throw new TypeError('The first argument to the callbackified function ' +\n+        'must be a callback style function');\n+    }\n+    var p = orig.call(this, ...args);\n+    if (typeof options.transformer === 'function') {\n+      p = options.transformer(p);\n+    }\n+    p = p.then((ret) => {\n+      if (toSplat) {\n+        cb(null, ...ret);\n+      } else if (project) {\n+        const allThere = project.all((k) => k in ret);\n+        if (!allThere) {\n+          const notAll = new TypeError('Not all of the projected properties' +\n+                                       ' are present in the returned value:' +\n+                                       inspect(ret));\n+          return cb(notAll);\n+        } else {\n+          const args = project.reduce((s, k) => s.concat(ret[k]), []);\n+          cb(null, ...args);\n+        }\n+      } else {\n+        cb(null, ret);\n+      }\n+    }, (rej) => {\n+      // !rej guard inspired by BlueBird https://goo.gl/t5IS6M\n+      if (!rej) {\n+        const newRej = new Error(rej + '');\n+        newRej.cause = rej;\n+        rej = newRej;\n+      }\n+      cb(rej);\n+    }).catch((e) => process.emit('uncaughtException', e));\n+    return p;","path":"lib/util.js","position":null,"original_position":67,"commit_id":"fa7ca2abd892312f7865324b5c50509be1a1e611","original_commit_id":"d5bb4784c2e944419d0ec1a5e962b2baf649e625","user":{"login":"refack","id":96947,"avatar_url":"https://avatars0.githubusercontent.com/u/96947?v=3","gravatar_id":"","url":"https://api.github.com/users/refack","html_url":"https://github.com/refack","followers_url":"https://api.github.com/users/refack/followers","following_url":"https://api.github.com/users/refack/following{/other_user}","gists_url":"https://api.github.com/users/refack/gists{/gist_id}","starred_url":"https://api.github.com/users/refack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/refack/subscriptions","organizations_url":"https://api.github.com/users/refack/orgs","repos_url":"https://api.github.com/users/refack/repos","events_url":"https://api.github.com/users/refack/events{/privacy}","received_events_url":"https://api.github.com/users/refack/received_events","type":"User","site_admin":false},"body":"Reason?","created_at":"2017-04-28T17:02:34Z","updated_at":"2017-04-28T17:02:34Z","html_url":"https://github.com/nodejs/node/pull/12712#discussion_r113975635","pull_request_url":"https://api.github.com/repos/nodejs/node/pulls/12712","_links":{"self":{"href":"https://api.github.com/repos/nodejs/node/pulls/comments/113975635"},"html":{"href":"https://github.com/nodejs/node/pull/12712#discussion_r113975635"},"pull_request":{"href":"https://api.github.com/repos/nodejs/node/pulls/12712"}}},"pull_request":{"url":"https://api.github.com/repos/nodejs/node/pulls/12712","id":118068299,"html_url":"https://github.com/nodejs/node/pull/12712","diff_url":"https://github.com/nodejs/node/pull/12712.diff","patch_url":"https://github.com/nodejs/node/pull/12712.patch","issue_url":"https://api.github.com/repos/nodejs/node/issues/12712","number":12712,"state":"open","locked":false,"title":"[WIP] util: add util.callbackify()","user":{"login":"refack","id":96947,"avatar_url":"https://avatars0.githubusercontent.com/u/96947?v=3","gravatar_id":"","url":"https://api.github.com/users/refack","html_url":"https://github.com/refack","followers_url":"https://api.github.com/users/refack/followers","following_url":"https://api.github.com/users/refack/following{/other_user}","gists_url":"https://api.github.com/users/refack/gists{/gist_id}","starred_url":"https://api.github.com/users/refack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/refack/subscriptions","organizations_url":"https://api.github.com/users/refack/orgs","repos_url":"https://api.github.com/users/refack/repos","events_url":"https://api.github.com/users/refack/events{/privacy}","received_events_url":"https://api.github.com/users/refack/received_events","type":"User","site_admin":false},"body":"This is a first draft of an implementation of `util.callbackify(function)`.\r\nThere is at least one issue that need ironing out: if and how to project the return value into multiple args...\r\n\r\nImplementation inspired by @addaleax's #12442\r\nBackground discussion at: https://github.com/nodejs/CTC/issues/109\r\n\r\n\r\n\r\n\r\n#### Original commit descriptions\r\n\r\n##### Add `util.callbackify(function)` for creating callback style functions\r\nfrom functions returning a `Promise`/`awaitable`\r\n\r\nFixes: https://github.com/nodejs/CTC/issues/109\r\n\r\n\r\n\r\n<!--\r\nThank you for your pull request. Please provide a description above and review\r\nthe requirements below.\r\n\r\nBug fixes and new features should include tests and possibly benchmarks.\r\n\r\nContributors guide: https://github.com/nodejs/node/blob/master/CONTRIBUTING.md\r\n-->\r\n\r\n##### Checklist\r\n<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->\r\n\r\n- [ ] `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes\r\n- [ ] tests and/or benchmarks are included\r\n- [ ] documentation is changed or added\r\n- [x] commit message follows [commit guidelines](https://github.com/nodejs/node/blob/master/CONTRIBUTING.md#commit-guidelines)\r\n\r\n##### Affected core subsystem(s)\r\nutil\r\n","created_at":"2017-04-28T02:22:53Z","updated_at":"2017-04-28T17:02:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4c792d53f6c05e336ce38e69d38e91b9b64269a7","assignee":{"login":"refack","id":96947,"avatar_url":"https://avatars0.githubusercontent.com/u/96947?v=3","gravatar_id":"","url":"https://api.github.com/users/refack","html_url":"https://github.com/refack","followers_url":"https://api.github.com/users/refack/followers","following_url":"https://api.github.com/users/refack/following{/other_user}","gists_url":"https://api.github.com/users/refack/gists{/gist_id}","starred_url":"https://api.github.com/users/refack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/refack/subscriptions","organizations_url":"https://api.github.com/users/refack/orgs","repos_url":"https://api.github.com/users/refack/repos","events_url":"https://api.github.com/users/refack/events{/privacy}","received_events_url":"https://api.github.com/users/refack/received_events","type":"User","site_admin":false},"assignees":[{"login":"refack","id":96947,"avatar_url":"https://avatars0.githubusercontent.com/u/96947?v=3","gravatar_id":"","url":"https://api.github.com/users/refack","html_url":"https://github.com/refack","followers_url":"https://api.github.com/users/refack/followers","following_url":"https://api.github.com/users/refack/following{/other_user}","gists_url":"https://api.github.com/users/refack/gists{/gist_id}","starred_url":"https://api.github.com/users/refack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/refack/subscriptions","organizations_url":"https://api.github.com/users/refack/orgs","repos_url":"https://api.github.com/users/refack/repos","events_url":"https://api.github.com/users/refack/events{/privacy}","received_events_url":"https://api.github.com/users/refack/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/nodejs/node/pulls/12712/commits","review_comments_url":"https://api.github.com/repos/nodejs/node/pulls/12712/comments","review_comment_url":"https://api.github.com/repos/nodejs/node/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nodejs/node/issues/12712/comments","statuses_url":"https://api.github.com/repos/nodejs/node/statuses/fa7ca2abd892312f7865324b5c50509be1a1e611","head":{"label":"refack:callbackify","ref":"callbackify","sha":"fa7ca2abd892312f7865324b5c50509be1a1e611","user":{"login":"refack","id":96947,"avatar_url":"https://avatars0.githubusercontent.com/u/96947?v=3","gravatar_id":"","url":"https://api.github.com/users/refack","html_url":"https://github.com/refack","followers_url":"https://api.github.com/users/refack/followers","following_url":"https://api.github.com/users/refack/following{/other_user}","gists_url":"https://api.github.com/users/refack/gists{/gist_id}","starred_url":"https://api.github.com/users/refack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/refack/subscriptions","organizations_url":"https://api.github.com/users/refack/orgs","repos_url":"https://api.github.com/users/refack/repos","events_url":"https://api.github.com/users/refack/events{/privacy}","received_events_url":"https://api.github.com/users/refack/received_events","type":"User","site_admin":false},"repo":{"id":81225016,"name":"node","full_name":"refack/node","owner":{"login":"refack","id":96947,"avatar_url":"https://avatars0.githubusercontent.com/u/96947?v=3","gravatar_id":"","url":"https://api.github.com/users/refack","html_url":"https://github.com/refack","followers_url":"https://api.github.com/users/refack/followers","following_url":"https://api.github.com/users/refack/following{/other_user}","gists_url":"https://api.github.com/users/refack/gists{/gist_id}","starred_url":"https://api.github.com/users/refack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/refack/subscriptions","organizations_url":"https://api.github.com/users/refack/orgs","repos_url":"https://api.github.com/users/refack/repos","events_url":"https://api.github.com/users/refack/events{/privacy}","received_events_url":"https://api.github.com/users/refack/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/refack/node","description":"Node.js JavaScript runtime :sparkles::turtle::rocket::sparkles:","fork":true,"url":"https://api.github.com/repos/refack/node","forks_url":"https://api.github.com/repos/refack/node/forks","keys_url":"https://api.github.com/repos/refack/node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/refack/node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/refack/node/teams","hooks_url":"https://api.github.com/repos/refack/node/hooks","issue_events_url":"https://api.github.com/repos/refack/node/issues/events{/number}","events_url":"https://api.github.com/repos/refack/node/events","assignees_url":"https://api.github.com/repos/refack/node/assignees{/user}","branches_url":"https://api.github.com/repos/refack/node/branches{/branch}","tags_url":"https://api.github.com/repos/refack/node/tags","blobs_url":"https://api.github.com/repos/refack/node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/refack/node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/refack/node/git/refs{/sha}","trees_url":"https://api.github.com/repos/refack/node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/refack/node/statuses/{sha}","languages_url":"https://api.github.com/repos/refack/node/languages","stargazers_url":"https://api.github.com/repos/refack/node/stargazers","contributors_url":"https://api.github.com/repos/refack/node/contributors","subscribers_url":"https://api.github.com/repos/refack/node/subscribers","subscription_url":"https://api.github.com/repos/refack/node/subscription","commits_url":"https://api.github.com/repos/refack/node/commits{/sha}","git_commits_url":"https://api.github.com/repos/refack/node/git/commits{/sha}","comments_url":"https://api.github.com/repos/refack/node/comments{/number}","issue_comment_url":"https://api.github.com/repos/refack/node/issues/comments{/number}","contents_url":"https://api.github.com/repos/refack/node/contents/{+path}","compare_url":"https://api.github.com/repos/refack/node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/refack/node/merges","archive_url":"https://api.github.com/repos/refack/node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/refack/node/downloads","issues_url":"https://api.github.com/repos/refack/node/issues{/number}","pulls_url":"https://api.github.com/repos/refack/node/pulls{/number}","milestones_url":"https://api.github.com/repos/refack/node/milestones{/number}","notifications_url":"https://api.github.com/repos/refack/node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/refack/node/labels{/name}","releases_url":"https://api.github.com/repos/refack/node/releases{/id}","deployments_url":"https://api.github.com/repos/refack/node/deployments","created_at":"2017-02-07T15:47:09Z","updated_at":"2017-03-14T22:19:54Z","pushed_at":"2017-04-28T17:01:11Z","git_url":"git://github.com/refack/node.git","ssh_url":"git@github.com:refack/node.git","clone_url":"https://github.com/refack/node.git","svn_url":"https://github.com/refack/node","homepage":"https://nodejs.org","size":282064,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"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":"nodejs:master","ref":"master","sha":"972bfe15143ff203bb576c1be69669e4e69dfb8d","user":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars0.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"repo":{"id":27193779,"name":"node","full_name":"nodejs/node","owner":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars0.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nodejs/node","description":"Node.js JavaScript runtime :sparkles::turtle::rocket::sparkles:","fork":false,"url":"https://api.github.com/repos/nodejs/node","forks_url":"https://api.github.com/repos/nodejs/node/forks","keys_url":"https://api.github.com/repos/nodejs/node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nodejs/node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nodejs/node/teams","hooks_url":"https://api.github.com/repos/nodejs/node/hooks","issue_events_url":"https://api.github.com/repos/nodejs/node/issues/events{/number}","events_url":"https://api.github.com/repos/nodejs/node/events","assignees_url":"https://api.github.com/repos/nodejs/node/assignees{/user}","branches_url":"https://api.github.com/repos/nodejs/node/branches{/branch}","tags_url":"https://api.github.com/repos/nodejs/node/tags","blobs_url":"https://api.github.com/repos/nodejs/node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nodejs/node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nodejs/node/git/refs{/sha}","trees_url":"https://api.github.com/repos/nodejs/node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nodejs/node/statuses/{sha}","languages_url":"https://api.github.com/repos/nodejs/node/languages","stargazers_url":"https://api.github.com/repos/nodejs/node/stargazers","contributors_url":"https://api.github.com/repos/nodejs/node/contributors","subscribers_url":"https://api.github.com/repos/nodejs/node/subscribers","subscription_url":"https://api.github.com/repos/nodejs/node/subscription","commits_url":"https://api.github.com/repos/nodejs/node/commits{/sha}","git_commits_url":"https://api.github.com/repos/nodejs/node/git/commits{/sha}","comments_url":"https://api.github.com/repos/nodejs/node/comments{/number}","issue_comment_url":"https://api.github.com/repos/nodejs/node/issues/comments{/number}","contents_url":"https://api.github.com/repos/nodejs/node/contents/{+path}","compare_url":"https://api.github.com/repos/nodejs/node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nodejs/node/merges","archive_url":"https://api.github.com/repos/nodejs/node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nodejs/node/downloads","issues_url":"https://api.github.com/repos/nodejs/node/issues{/number}","pulls_url":"https://api.github.com/repos/nodejs/node/pulls{/number}","milestones_url":"https://api.github.com/repos/nodejs/node/milestones{/number}","notifications_url":"https://api.github.com/repos/nodejs/node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nodejs/node/labels{/name}","releases_url":"https://api.github.com/repos/nodejs/node/releases{/id}","deployments_url":"https://api.github.com/repos/nodejs/node/deployments","created_at":"2014-11-26T19:57:11Z","updated_at":"2017-04-28T15:52:04Z","pushed_at":"2017-04-28T17:01:22Z","git_url":"git://github.com/nodejs/node.git","ssh_url":"git@github.com:nodejs/node.git","clone_url":"https://github.com/nodejs/node.git","svn_url":"https://github.com/nodejs/node","homepage":"https://nodejs.org","size":280338,"stargazers_count":34350,"watchers_count":34350,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6558,"mirror_url":null,"open_issues_count":1063,"forks":6558,"open_issues":1063,"watchers":34350,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nodejs/node/pulls/12712"},"html":{"href":"https://github.com/nodejs/node/pull/12712"},"issue":{"href":"https://api.github.com/repos/nodejs/node/issues/12712"},"comments":{"href":"https://api.github.com/repos/nodejs/node/issues/12712/comments"},"review_comments":{"href":"https://api.github.com/repos/nodejs/node/pulls/12712/comments"},"review_comment":{"href":"https://api.github.com/repos/nodejs/node/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nodejs/node/pulls/12712/commits"},"statuses":{"href":"https://api.github.com/repos/nodejs/node/statuses/fa7ca2abd892312f7865324b5c50509be1a1e611"}}}}
{"actor":{"display_login":"refack"}}