{"action":"created","issue":{"url":"https://api.github.com/repos/zenparsing/es-cancel-token/issues/6","repository_url":"https://api.github.com/repos/zenparsing/es-cancel-token","labels_url":"https://api.github.com/repos/zenparsing/es-cancel-token/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/zenparsing/es-cancel-token/issues/6/comments","events_url":"https://api.github.com/repos/zenparsing/es-cancel-token/issues/6/events","html_url":"https://github.com/zenparsing/es-cancel-token/issues/6","id":157681857,"number":6,"title":"The ability to compose tokens","user":{"login":"blesh","id":1540597,"avatar_url":"https://avatars.githubusercontent.com/u/1540597?v=3","gravatar_id":"","url":"https://api.github.com/users/blesh","html_url":"https://github.com/blesh","followers_url":"https://api.github.com/users/blesh/followers","following_url":"https://api.github.com/users/blesh/following{/other_user}","gists_url":"https://api.github.com/users/blesh/gists{/gist_id}","starred_url":"https://api.github.com/users/blesh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blesh/subscriptions","organizations_url":"https://api.github.com/users/blesh/orgs","repos_url":"https://api.github.com/users/blesh/repos","events_url":"https://api.github.com/users/blesh/events{/privacy}","received_events_url":"https://api.github.com/users/blesh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-31T14:13:05Z","updated_at":"2016-05-31T14:53:25Z","closed_at":null,"body":"The idea here is that you can combine tokens so one token's cancellation can be linked to another. This would make CancelToken more useful for composing chains of async, as found in RxJS or other observable libraries. For example:\r\n\r\n\r\n```js\r\nlet token1 = new CancelToken();\r\nlet token2 = new CancelToken();\r\n\r\ntoken1.add(token2);\r\n\r\ntoken1.cancel(); // both 1 and 2 are cancelled\r\n```\r\n\r\n\r\n```js\r\nlet token1 = new CancelToken();\r\nlet token2 = new CancelToken();\r\n\r\ntoken1.add(token2);\r\n\r\ntoken2.cancel(); // only 2 is cancelled\r\n```\r\n\r\n\r\n```js\r\nlet token1 = new CancelToken();\r\nlet token2 = new CancelToken();\r\n\r\ntoken1.add(token2);\r\ntoken2.add(token1);\r\n\r\ntoken2.cancel(); // both 1 and 2 are cancelled\r\n```\r\n\r\n\r\n\r\n```js\r\nlet token1 = new CancelToken();\r\nlet token2 = new CancelToken();\r\nlet token3 = new CancelToken();\r\n\r\ntoken1.add(token2);\r\ntoken2.add(token2);\r\n\r\ntoken1.cancel(); // both 1 and 2 are cancelled, not 3\r\n```\r\n\r\n\r\n\r\n```js\r\nlet token1 = new CancelToken();\r\nlet token2 = new CancelToken();\r\nlet token3 = new CancelToken();\r\n\r\ntoken1.add(token2);\r\ntoken2.add(token2);\r\n\r\ntoken2.cancel(); // only 2 is cancelled\r\n```"},"comment":{"url":"https://api.github.com/repos/zenparsing/es-cancel-token/issues/comments/222713712","html_url":"https://github.com/zenparsing/es-cancel-token/issues/6#issuecomment-222713712","issue_url":"https://api.github.com/repos/zenparsing/es-cancel-token/issues/6","id":222713712,"user":{"login":"domenic","id":617481,"avatar_url":"https://avatars.githubusercontent.com/u/617481?v=3","gravatar_id":"","url":"https://api.github.com/users/domenic","html_url":"https://github.com/domenic","followers_url":"https://api.github.com/users/domenic/followers","following_url":"https://api.github.com/users/domenic/following{/other_user}","gists_url":"https://api.github.com/users/domenic/gists{/gist_id}","starred_url":"https://api.github.com/users/domenic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/domenic/subscriptions","organizations_url":"https://api.github.com/users/domenic/orgs","repos_url":"https://api.github.com/users/domenic/repos","events_url":"https://api.github.com/users/domenic/events{/privacy}","received_events_url":"https://api.github.com/users/domenic/received_events","type":"User","site_admin":false},"created_at":"2016-05-31T14:53:25Z","updated_at":"2016-05-31T14:53:25Z","body":"Yes, this use case generally make sense to me. We should probably look to .NET for inspiration at least in breadth of API. I'd appreciate some small motivating real-worldish examples. (Preferably for application authors, since that's easier to explain, although of course library authors are super-important as well.)\r\n\r\nIs a mutable API important, or is it possible to achieve the same thing with a (cancel token, cancel token) -> cancel token combinator? For example, if you posit a combinator `CancelToken.cancelBoth(t1, t2)` which returns a `cancel` function that cancels both `t1` and `t2`, I think I can rewrite all your above examples to work.\r\n\r\nBut I'm not sure I entirely understand the point of your examples, as they seem to be illustrating mechanism, not use case---for example the second example would behave the same if you removed the `.add()` call entirely."}}
{"actor":{"display_login":"domenic"}}