{"action":"created","issue":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/1148","repository_url":"https://api.github.com/repos/petkaantonov/bluebird","labels_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/1148/labels{/name}","comments_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/1148/comments","events_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/1148/events","html_url":"https://github.com/petkaantonov/bluebird/issues/1148","id":162355231,"number":1148,"title":"`Promise.map` calls callback synchronously in bluebird v3.x","user":{"login":"overlookmotel","id":557937,"avatar_url":"https://avatars.githubusercontent.com/u/557937?v=3","gravatar_id":"","url":"https://api.github.com/users/overlookmotel","html_url":"https://github.com/overlookmotel","followers_url":"https://api.github.com/users/overlookmotel/followers","following_url":"https://api.github.com/users/overlookmotel/following{/other_user}","gists_url":"https://api.github.com/users/overlookmotel/gists{/gist_id}","starred_url":"https://api.github.com/users/overlookmotel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/overlookmotel/subscriptions","organizations_url":"https://api.github.com/users/overlookmotel/orgs","repos_url":"https://api.github.com/users/overlookmotel/repos","events_url":"https://api.github.com/users/overlookmotel/events{/privacy}","received_events_url":"https://api.github.com/users/overlookmotel/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/petkaantonov/bluebird/labels/4.0.0","name":"4.0.0","color":"0052cc"},{"url":"https://api.github.com/repos/petkaantonov/bluebird/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2016-06-27T00:08:08Z","updated_at":"2016-09-01T07:52:35Z","closed_at":"2016-09-01T07:05:00Z","body":"1) What version of bluebird is the issue happening on?\r\n\r\nv3.0.0-3.4.1\r\n\r\n2) What platform and version? (For example Node.js 0.12 or Google Chrome 32)\r\n\r\nNode v6.2.1, OS X 10.9.5\r\n\r\n3) Did this issue happen with earlier version of bluebird?\r\n\r\nNo\r\n\r\n---\r\n\r\n#### `Promise.map()` calling callback sync/async\r\n\r\nThe behavior of `Promise.map()` seems to have changed between bluebird v2.10.2 and v3.0.0.\r\n\r\nIn v2.x, the callback is always called asynchronously; in v3.0.0-3.4.1 the callback is called synchronously for literal values of the array.\r\n\r\n```js\r\nvar arr = [ 1, 2, 3 ];\r\nPromise.map( arr, function(v) {\r\n    console.log(v);\r\n} );\r\nconsole.log('next sync statement');\r\n```\r\n\r\nWith bluebird v2.10.2:\r\n\r\n```\r\nnext sync statement\r\n1\r\n2\r\n3\r\n```\r\n\r\nWith bluebird v3.x:\r\n\r\n```\r\n1\r\n2\r\n3\r\nnext sync statement\r\n```\r\n\r\nResolved promises in the array are also mapped over synchronously. e.g. `arr = [ 1, Promise.resolve(2), 3 ]`, gives the same result.\r\n\r\nBut any unresolved promises in the array are awaited before calling the callback on that item. This causes some puzzling behavior:\r\n\r\n```js\r\nvar arr = [ 1, Promise.resolve(2).tap( function() {} ), 3 ];\r\nPromise.map( arr, function(v) {\r\n    console.log(v);\r\n} );\r\nconsole.log('next sync statement');\r\n```\r\n\r\nOutputs:\r\n\r\n```\r\n1\r\n3\r\nnext sync statement\r\n2\r\n```\r\n\r\nAnd also:\r\n\r\n```js\r\nvar iterator = (function*() {\r\n    yield 1;\r\n    yield Promise.resolve(2).tap(function() {});\r\n    yield 3;\r\n})();\r\n\r\nPromise.map( iterator, function(v) {\r\n    console.log(v);\r\n} );\r\nconsole.log('next sync statement');\r\n```\r\n\r\n```\r\n1\r\n3\r\nnext sync statement\r\n2\r\n```\r\n\r\nThis behavior is the same with `Promise.filter()` too.\r\n\r\n#### Questions\r\n\r\n1. Was this change in behavior intended? (If so, I feel it should be noted in the docs)\r\n2. If it wasn't intended, would this be considered Zalgo?\r\n3. Is it inconsistent that `Promise.mapSeries()` doesn't call the callback syncronously for the first round?"},"comment":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/comments/244003422","html_url":"https://github.com/petkaantonov/bluebird/issues/1148#issuecomment-244003422","issue_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/1148","id":244003422,"user":{"login":"benjamingr","id":1315533,"avatar_url":"https://avatars.githubusercontent.com/u/1315533?v=3","gravatar_id":"","url":"https://api.github.com/users/benjamingr","html_url":"https://github.com/benjamingr","followers_url":"https://api.github.com/users/benjamingr/followers","following_url":"https://api.github.com/users/benjamingr/following{/other_user}","gists_url":"https://api.github.com/users/benjamingr/gists{/gist_id}","starred_url":"https://api.github.com/users/benjamingr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjamingr/subscriptions","organizations_url":"https://api.github.com/users/benjamingr/orgs","repos_url":"https://api.github.com/users/benjamingr/repos","events_url":"https://api.github.com/users/benjamingr/events{/privacy}","received_events_url":"https://api.github.com/users/benjamingr/received_events","type":"User","site_admin":false},"created_at":"2016-09-01T07:52:35Z","updated_at":"2016-09-01T07:52:35Z","body":"Thanks!"}}
{"actor":{"display_login":"benjamingr"}}