{"action":"created","issue":{"url":"https://api.github.com/repos/joyent/node/issues/6011","labels_url":"https://api.github.com/repos/joyent/node/issues/6011/labels{/name}","comments_url":"https://api.github.com/repos/joyent/node/issues/6011/comments","events_url":"https://api.github.com/repos/joyent/node/issues/6011/events","html_url":"https://github.com/joyent/node/pull/6011","id":17766707,"number":6011,"title":"implement domain-like hooks for userland","user":{"login":"trevnorris","id":289174,"avatar_url":"https://avatars.githubusercontent.com/u/289174?v=3","gravatar_id":"","url":"https://api.github.com/users/trevnorris","html_url":"https://github.com/trevnorris","followers_url":"https://api.github.com/users/trevnorris/followers","following_url":"https://api.github.com/users/trevnorris/following{/other_user}","gists_url":"https://api.github.com/users/trevnorris/gists{/gist_id}","starred_url":"https://api.github.com/users/trevnorris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trevnorris/subscriptions","organizations_url":"https://api.github.com/users/trevnorris/orgs","repos_url":"https://api.github.com/users/trevnorris/repos","events_url":"https://api.github.com/users/trevnorris/events{/privacy}","received_events_url":"https://api.github.com/users/trevnorris/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/joyent/node/labels/asynclistener","name":"asynclistener","color":"e11d21"},{"url":"https://api.github.com/repos/joyent/node/labels/master","name":"master","color":"5319e7"},{"url":"https://api.github.com/repos/joyent/node/labels/pr","name":"pr","color":"006b75"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":26,"created_at":"2013-08-07T18:56:10Z","updated_at":"2015-06-30T08:05:21Z","closed_at":"2013-11-01T19:10:31Z","pull_request":{"url":"https://api.github.com/repos/joyent/node/pulls/6011","html_url":"https://github.com/joyent/node/pull/6011","diff_url":"https://github.com/joyent/node/pull/6011.diff","patch_url":"https://github.com/joyent/node/pull/6011.patch"},"body":"Here's the current API planned for implementation:\r\n```javascript\r\n// Class that will store information about a specific request.\r\nfunction Storage() { }\r\n\r\n// This will be called every time asynchronous work is queued.\r\n// The returned data will propagate to the callbackObject's callbacks.\r\nfunction onCreation() {\r\n  return new Storage();\r\n}\r\n\r\n// Set of methods that will run at specific points in time according to\r\n// their cooresponding callbacks. These methods are always run FIFO if\r\n// multiple are queued.\r\n// \"context\" is the \"this\" of the request object.\r\nvar callbackObject = {\r\n  before: function asyncBefore(context, storageValue) {\r\n  },\r\n  // \"returnValue\" is the value returned from the callback.\r\n  after: function asyncAfter(context, storageValue) {\r\n  },\r\n  // If this callback returns \"true\" then the error handler will assume\r\n  // the error was properly handled, and process will continue normally.\r\n  // If multiple error handlers are queued, and any one of those returns\r\n  // true, then Node will assume the error was properly handled.\r\n  // This will not currently be passed the context (or \"this\") of the\r\n  // callback that threw. A simple way of achieving this is currently\r\n  // being investigated, and the feature will be added when one is found.\r\n  error: function asyncError(storageValue, err) {\r\n  }\r\n};\r\n\r\n/**\r\n * process.addAsyncListener(callback[, object[, value]]);\r\n *\r\n * Arguments:\r\n *\r\n * callback - Function that will be run when an asynchronous job is\r\n *    queued.\r\n *\r\n * object - Object with the optional callbacks set on:\r\n *    before - Callback called just before the asynchronous callback\r\n *        will be called.\r\n *    after - Callback called directly after the asynchronous callback.\r\n *    error - Callback called if there was an error.\r\n *\r\n * The returned key is an Object that serves as the unique key for the\r\n * call (much like how Timers work).\r\n */\r\nvar key = process.addAsyncListener(onAsync, callbackObject);\r\n\r\n\r\n/**\r\n * process.createAsyncListener(callback[, object[, value]]);\r\n *\r\n * Adding an async listener will immediately add it to the queue and\r\n * being listening for events. If you wish to create the listener in\r\n * advance, to say attach to the returned value object, it's possible\r\n * to get the key and pass it to process.addAsyncListener() later.\r\n */\r\nvar key = process.createAsyncListener(onAsync, callbackObject, value);\r\n\r\n// Then activate like so:\r\nprocess.addAsyncListener(key);\r\n\r\n\r\n/**\r\n * process.removeAsyncListener(key);\r\n *\r\n * Remove any async listeners and associated callbackObjects. All\r\n * listeners will live independent of each other, and there will be no\r\n * method given to clear all async listeners.\r\n */\r\nprocess.removeAsyncListener(key);\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/joyent/node/issues/comments/117048977","html_url":"https://github.com/joyent/node/pull/6011#issuecomment-117048977","issue_url":"https://api.github.com/repos/joyent/node/issues/6011","id":117048977,"user":{"login":"gobwas","id":675117,"avatar_url":"https://avatars.githubusercontent.com/u/675117?v=3","gravatar_id":"","url":"https://api.github.com/users/gobwas","html_url":"https://github.com/gobwas","followers_url":"https://api.github.com/users/gobwas/followers","following_url":"https://api.github.com/users/gobwas/following{/other_user}","gists_url":"https://api.github.com/users/gobwas/gists{/gist_id}","starred_url":"https://api.github.com/users/gobwas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gobwas/subscriptions","organizations_url":"https://api.github.com/users/gobwas/orgs","repos_url":"https://api.github.com/users/gobwas/repos","events_url":"https://api.github.com/users/gobwas/events{/privacy}","received_events_url":"https://api.github.com/users/gobwas/received_events","type":"User","site_admin":false},"created_at":"2015-06-30T08:05:21Z","updated_at":"2015-06-30T08:05:21Z","body":"So, will node have this feature some day?"}}