{"action":"created","issue":{"url":"https://api.github.com/repos/othiym23/async-listener/issues/59","repository_url":"https://api.github.com/repos/othiym23/async-listener","labels_url":"https://api.github.com/repos/othiym23/async-listener/issues/59/labels{/name}","comments_url":"https://api.github.com/repos/othiym23/async-listener/issues/59/comments","events_url":"https://api.github.com/repos/othiym23/async-listener/issues/59/events","html_url":"https://github.com/othiym23/async-listener/issues/59","id":162198298,"number":59,"title":"Promise.all context propagation","user":{"login":"jbellenger","id":1391805,"avatar_url":"https://avatars.githubusercontent.com/u/1391805?v=3","gravatar_id":"","url":"https://api.github.com/users/jbellenger","html_url":"https://github.com/jbellenger","followers_url":"https://api.github.com/users/jbellenger/followers","following_url":"https://api.github.com/users/jbellenger/following{/other_user}","gists_url":"https://api.github.com/users/jbellenger/gists{/gist_id}","starred_url":"https://api.github.com/users/jbellenger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbellenger/subscriptions","organizations_url":"https://api.github.com/users/jbellenger/orgs","repos_url":"https://api.github.com/users/jbellenger/repos","events_url":"https://api.github.com/users/jbellenger/events{/privacy}","received_events_url":"https://api.github.com/users/jbellenger/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-06-24T17:55:23Z","updated_at":"2016-07-11T16:27:43Z","closed_at":null,"body":"Async-listener will propagate contexts through Promise.all, which is different behavior from similar functionality in the domain module.\r\n\r\nIt's not 100% clear to me that this is a bug, though it is unexpected. \r\n\r\nTest case:\r\n```javascript\r\n'use strict';\r\n\r\n// CLS\r\n(() => {\r\n  const cls = require('continuation-local-storage');\r\n  const ns = cls.createNamespace('ns');\r\n  const promises = [];\r\n\r\n  for (let i=0; i < 3; i++) {\r\n    const p = new Promise((resolve) => {\r\n      ns.run(() => {\r\n        ns.active.i = i;\r\n        resolve(i)\r\n      });\r\n    });\r\n\r\n    promises.push(p);\r\n  }\r\n\r\n  Promise.all(promises)\r\n    .then(() => {\r\n      console.log('[CLS] Promise.all active ns', ns.active);\r\n    });\r\n})();\r\n\r\n// domain\r\n(() => {\r\n  const domain = require('domain');\r\n  const d = domain.createDomain();\r\n  const promises = [];\r\n\r\n  for (let i=0; i < 3; i++) {\r\n    const p = new Promise((resolve) => {\r\n      d.run(() => {\r\n        domain.active.i = i;\r\n        resolve(i);\r\n      });\r\n    });\r\n\r\n    promises.push(p);\r\n  };\r\n\r\n  Promise.all(promises)\r\n    .then(() => {\r\n      console.log('[Domain] Promise.all active domain', d.active);\r\n    });\r\n})();\r\n``` \r\n\r\nOutput:\r\n```\r\n$ node -version\r\nv6.2.2\r\n\r\n$ node cls-test.js\r\n[CLS] Promise.all active ns { i: 2 }\r\n[Domain] Promise.all active domain undefined\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/othiym23/async-listener/issues/comments/231787603","html_url":"https://github.com/othiym23/async-listener/issues/59#issuecomment-231787603","issue_url":"https://api.github.com/repos/othiym23/async-listener/issues/59","id":231787603,"user":{"login":"hayes","id":816527,"avatar_url":"https://avatars.githubusercontent.com/u/816527?v=3","gravatar_id":"","url":"https://api.github.com/users/hayes","html_url":"https://github.com/hayes","followers_url":"https://api.github.com/users/hayes/followers","following_url":"https://api.github.com/users/hayes/following{/other_user}","gists_url":"https://api.github.com/users/hayes/gists{/gist_id}","starred_url":"https://api.github.com/users/hayes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hayes/subscriptions","organizations_url":"https://api.github.com/users/hayes/orgs","repos_url":"https://api.github.com/users/hayes/repos","events_url":"https://api.github.com/users/hayes/events{/privacy}","received_events_url":"https://api.github.com/users/hayes/received_events","type":"User","site_admin":false},"created_at":"2016-07-11T16:27:43Z","updated_at":"2016-07-11T16:27:43Z","body":"This is by design, although there is a lot of debate as too the correct approach. There is currently an open issue on CLS discussig how promises should propagate contexts.  The approach asl took was to propagate from resolution to callback rather than creation to callback.  For example, if a promise wraps an api that makes a network request, the callback passed to then would be a child of that request rather than a sibling. This allows consumers of the asl api to trace causality. In the Promise.all case, the thing resolving the promise is the same thing as.tge last promise to.resolve that was passed to all."}}
{"actor":{"display_login":"hayes"}}