{"action":"created","issue":{"url":"https://api.github.com/repos/balderdashy/waterline/issues/983","labels_url":"https://api.github.com/repos/balderdashy/waterline/issues/983/labels{/name}","comments_url":"https://api.github.com/repos/balderdashy/waterline/issues/983/comments","events_url":"https://api.github.com/repos/balderdashy/waterline/issues/983/events","html_url":"https://github.com/balderdashy/waterline/issues/983","id":72224349,"number":983,"title":"Make .exec() return promise when no callback is provided. (To be used with generators/node-fibers async workflow)","user":{"login":"Zaggen","id":6466844,"avatar_url":"https://avatars.githubusercontent.com/u/6466844?v=3","gravatar_id":"","url":"https://api.github.com/users/Zaggen","html_url":"https://github.com/Zaggen","followers_url":"https://api.github.com/users/Zaggen/followers","following_url":"https://api.github.com/users/Zaggen/following{/other_user}","gists_url":"https://api.github.com/users/Zaggen/gists{/gist_id}","starred_url":"https://api.github.com/users/Zaggen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zaggen/subscriptions","organizations_url":"https://api.github.com/users/Zaggen/orgs","repos_url":"https://api.github.com/users/Zaggen/repos","events_url":"https://api.github.com/users/Zaggen/events{/privacy}","received_events_url":"https://api.github.com/users/Zaggen/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/balderdashy/waterline/labels/feature","name":"feature","color":"207de5"},{"url":"https://api.github.com/repos/balderdashy/waterline/labels/needs%20community%20feedback","name":"needs community feedback","color":"009800"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-04-30T17:17:20Z","updated_at":"2015-06-08T21:03:24Z","closed_at":"2015-06-08T21:00:29Z","body":"When using promises in waterline models is necessary to call **then** to execute the query, which is perfect, but if one is using synchronous-like workflow by using generators or a library like [asyncawait](https://github.com/yortus/asyncawait) or [co](https://github.com/tj/co) or even [ES7 async/await](https://github.com/lukehoban/ecmascript-asyncawait) in the future, calling **.then** sounds confusing when reading it. So i'm proposing a little syntactic sugar to use in these cases.\r\nMaking **exec** to return a promise when called with no callback argument, or an alias like **defer** or **execAsync**  to the **then** method.\r\n\r\nHere is the current workflow using **ES7 async/await** (Just for simplicity):\r\nNote: When using a library like **yortus asyncawait**, those keywords are actually **functions** and when using using **generators**, the **yield** keyword is used instead of await.\r\n\r\n```javascript\r\n// Some requires\r\nvar User = Waterline.Collection.extend({/* ... */}});\r\nasync function() {\r\n    try {\r\n      var data = await User.find().then();\r\n      console.log('results', data);\r\n    } catch (error) {\r\n      // Handle error\r\n    }\r\n}\r\n```\r\nProposed sugar method worflow\r\n```javascript\r\n// Some requires\r\nvar User = Waterline.Collection.extend({/* ... */});\r\nasync function() {\r\n    try {\r\n      var data = await User.find().exec();\r\n      console.log('results', data);\r\n    } catch (error) {\r\n      // Handle error\r\n    }\r\n}\r\n```\r\nI think this feature makes makes the code more readable when using this kind of workflow, which is something we all probably will be using in the near future, if not already....\r\n\r\nPst: This is my first time proposing a feature here, if i made a mistake, please let me know :)"},"comment":{"url":"https://api.github.com/repos/balderdashy/waterline/issues/comments/110139815","html_url":"https://github.com/balderdashy/waterline/issues/983#issuecomment-110139815","issue_url":"https://api.github.com/repos/balderdashy/waterline/issues/983","id":110139815,"user":{"login":"dmarcelino","id":1280446,"avatar_url":"https://avatars.githubusercontent.com/u/1280446?v=3","gravatar_id":"","url":"https://api.github.com/users/dmarcelino","html_url":"https://github.com/dmarcelino","followers_url":"https://api.github.com/users/dmarcelino/followers","following_url":"https://api.github.com/users/dmarcelino/following{/other_user}","gists_url":"https://api.github.com/users/dmarcelino/gists{/gist_id}","starred_url":"https://api.github.com/users/dmarcelino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmarcelino/subscriptions","organizations_url":"https://api.github.com/users/dmarcelino/orgs","repos_url":"https://api.github.com/users/dmarcelino/repos","events_url":"https://api.github.com/users/dmarcelino/events{/privacy}","received_events_url":"https://api.github.com/users/dmarcelino/received_events","type":"User","site_admin":false},"created_at":"2015-06-08T21:03:24Z","updated_at":"2015-06-08T21:03:24Z","body":"Good to know it works, thanks for letting us know!"}}