{"action":"opened","issue":{"url":"https://api.github.com/repos/NodeBB/NodeBB/issues/6444","repository_url":"https://api.github.com/repos/NodeBB/NodeBB","labels_url":"https://api.github.com/repos/NodeBB/NodeBB/issues/6444/labels{/name}","comments_url":"https://api.github.com/repos/NodeBB/NodeBB/issues/6444/comments","events_url":"https://api.github.com/repos/NodeBB/NodeBB/issues/6444/events","html_url":"https://github.com/NodeBB/NodeBB/issues/6444","id":312916137,"number":6444,"title":"Support Promise and AsyncFunction as new method of hook","user":{"login":"a632079","id":16975812,"avatar_url":"https://avatars1.githubusercontent.com/u/16975812?v=4","gravatar_id":"","url":"https://api.github.com/users/a632079","html_url":"https://github.com/a632079","followers_url":"https://api.github.com/users/a632079/followers","following_url":"https://api.github.com/users/a632079/following{/other_user}","gists_url":"https://api.github.com/users/a632079/gists{/gist_id}","starred_url":"https://api.github.com/users/a632079/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/a632079/subscriptions","organizations_url":"https://api.github.com/users/a632079/orgs","repos_url":"https://api.github.com/users/a632079/repos","events_url":"https://api.github.com/users/a632079/events{/privacy}","received_events_url":"https://api.github.com/users/a632079/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-10T13:12:06Z","updated_at":"2018-04-10T13:12:06Z","closed_at":null,"author_association":"NONE","body":"ES6 brinsg `Promise`, a syntactic sugar of callback-function, support more friendly error handler without dropping handing stack.\r\nFor example,\r\n```\r\nPromise.resolve(1)\r\n  .then(d => {\r\n    throw new Error(\"crash\")\r\n  })\r\n  .catch(e => {\r\n     console.log(\"can catch err, without dropping stack\")\r\n  })\r\n```\r\nA suggested method:\r\n```\r\nclass A {\r\n  static getUser(params) {\r\n    return new Promise((ok, err) => {\r\n       // handle\r\n    });\r\n  }\r\n  static async getData(params) {\r\n     return data;\r\n  }\r\n}\r\nmodule.exports = A\r\n```\r\nA common method:\r\n```\r\nmodule.exports = {\r\n  getUser: (params) => {\r\n    return new Promise((ok, err) => {\r\n      // Handle\r\n    })\r\n  }\r\n  getData: async (params) => {\r\n    // handle\r\n  }\r\n}\r\n```\r\nWe might can support it via `typeof` and `method.length`"}}
{"actor":{"display_login":"a632079"}}