{"action":"created","issue":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/4780","labels_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/4780/labels{/name}","comments_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/4780/comments","events_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/4780/events","html_url":"https://github.com/rethinkdb/rethinkdb/issues/4780","id":104127421,"number":4780,"title":"(Javascript) Make `each()` return a Promise","user":{"login":"jorrit","id":521449,"avatar_url":"https://avatars.githubusercontent.com/u/521449?v=3","gravatar_id":"","url":"https://api.github.com/users/jorrit","html_url":"https://github.com/jorrit","followers_url":"https://api.github.com/users/jorrit/followers","following_url":"https://api.github.com/users/jorrit/following{/other_user}","gists_url":"https://api.github.com/users/jorrit/gists{/gist_id}","starred_url":"https://api.github.com/users/jorrit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jorrit/subscriptions","organizations_url":"https://api.github.com/users/jorrit/orgs","repos_url":"https://api.github.com/users/jorrit/repos","events_url":"https://api.github.com/users/jorrit/events{/privacy}","received_events_url":"https://api.github.com/users/jorrit/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-08-31T20:24:03Z","updated_at":"2015-08-31T21:02:44Z","closed_at":null,"body":"Each iteration of `each()` is done asynchronously. In the following code, close would be called before the second iteration of each:\r\n\r\n```javascript\r\ncursor.each(async (err, data) => {\r\n  if(err) throw err;\r\n  await dosomethingasynchronouslywithdata();\r\n});\r\nawait conn.close();\r\n```\r\n\r\nAlmost all methods offer the choice between a callback and a Promise. `each` is an exception: it only offers an `onFinished` callback, but it doesn't return a `Promise`. If this were done, the code would look like:\r\n\r\n```javascript\r\nawait cursor.each(async (err, data) => {\r\n  if(err) throw err;\r\n  await dosomethingasynchronouslywithdata();\r\n});\r\nawait conn.close();\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/comments/136498402","html_url":"https://github.com/rethinkdb/rethinkdb/issues/4780#issuecomment-136498402","issue_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/4780","id":136498402,"user":{"login":"deontologician","id":1366,"avatar_url":"https://avatars.githubusercontent.com/u/1366?v=3","gravatar_id":"","url":"https://api.github.com/users/deontologician","html_url":"https://github.com/deontologician","followers_url":"https://api.github.com/users/deontologician/followers","following_url":"https://api.github.com/users/deontologician/following{/other_user}","gists_url":"https://api.github.com/users/deontologician/gists{/gist_id}","starred_url":"https://api.github.com/users/deontologician/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deontologician/subscriptions","organizations_url":"https://api.github.com/users/deontologician/orgs","repos_url":"https://api.github.com/users/deontologician/repos","events_url":"https://api.github.com/users/deontologician/events{/privacy}","received_events_url":"https://api.github.com/users/deontologician/received_events","type":"User","site_admin":false},"created_at":"2015-08-31T21:02:44Z","updated_at":"2015-08-31T21:02:44Z","body":"I'm definitely open to PRs on this, it will be a little while before I could get to it"}}