{"action":"created","issue":{"url":"https://api.github.com/repos/flatiron/prompt/issues/81","labels_url":"https://api.github.com/repos/flatiron/prompt/issues/81/labels{/name}","comments_url":"https://api.github.com/repos/flatiron/prompt/issues/81/comments","events_url":"https://api.github.com/repos/flatiron/prompt/issues/81/events","html_url":"https://github.com/flatiron/prompt/issues/81","id":27830352,"number":81,"title":"[feature request] return a promise from prompt.get()","user":{"login":"jblashill","id":1558017,"avatar_url":"https://avatars.githubusercontent.com/u/1558017?v=3","gravatar_id":"","url":"https://api.github.com/users/jblashill","html_url":"https://github.com/jblashill","followers_url":"https://api.github.com/users/jblashill/followers","following_url":"https://api.github.com/users/jblashill/following{/other_user}","gists_url":"https://api.github.com/users/jblashill/gists{/gist_id}","starred_url":"https://api.github.com/users/jblashill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jblashill/subscriptions","organizations_url":"https://api.github.com/users/jblashill/orgs","repos_url":"https://api.github.com/users/jblashill/repos","events_url":"https://api.github.com/users/jblashill/events{/privacy}","received_events_url":"https://api.github.com/users/jblashill/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2014-02-18T21:41:37Z","updated_at":"2015-02-17T01:15:12Z","closed_at":"2015-02-16T22:56:59Z","body":"I've found that wrapping prompt() in a method that returns a promise has lead to cleaner and more maintainable code. That is, I do something like this:\r\n\r\n```javascript\r\nvar promptUser = function(schema) {\r\n  return new Promise(resolve, reject) {\r\n    prompt.get(schema, function(err, result) {\r\n      if (err) {\r\n        reject(err);\r\n      } else {\r\n        resolve(result);\r\n      }\r\n    });\r\n  };\r\n};\r\n```\r\n\r\nThis allows me to write expressive code like (omitting function details):\r\n\r\n```javascript\r\npromptUser([\"name\", \"email\", \"password\"])\r\n  .then(addUserToDb)\r\n  .then(sendUserEmail)\r\n  .then(printUser)\r\n  .catch(printError);\r\n```\r\n\r\nIt would be great if rather than using the callback in prompt.get() if you could also return a promise as well. It's a minor thing since it's so easy to wrap the call but I think it's worthwhile to promote.\r\n\r\nFYI, the promises API used above is this polyfill for the ES6 Promises API: https://github.com/jakearchibald/es6-promise\r\n\r\nThanks for the consideration!"},"comment":{"url":"https://api.github.com/repos/flatiron/prompt/issues/comments/74602648","html_url":"https://github.com/flatiron/prompt/issues/81#issuecomment-74602648","issue_url":"https://api.github.com/repos/flatiron/prompt/issues/81","id":74602648,"user":{"login":"jcrugzz","id":592149,"avatar_url":"https://avatars.githubusercontent.com/u/592149?v=3","gravatar_id":"","url":"https://api.github.com/users/jcrugzz","html_url":"https://github.com/jcrugzz","followers_url":"https://api.github.com/users/jcrugzz/followers","following_url":"https://api.github.com/users/jcrugzz/following{/other_user}","gists_url":"https://api.github.com/users/jcrugzz/gists{/gist_id}","starred_url":"https://api.github.com/users/jcrugzz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcrugzz/subscriptions","organizations_url":"https://api.github.com/users/jcrugzz/orgs","repos_url":"https://api.github.com/users/jcrugzz/repos","events_url":"https://api.github.com/users/jcrugzz/events{/privacy}","received_events_url":"https://api.github.com/users/jcrugzz/received_events","type":"User","site_admin":false},"created_at":"2015-02-17T01:15:12Z","updated_at":"2015-02-17T01:15:12Z","body":"@jblashill seems like you can get something like this sometime soon using [`babel`](https://github.com/babel/babel). And no problem :)"}}