{"action":"created","issue":{"url":"https://api.github.com/repos/zenparsing/es-observable/issues/99","repository_url":"https://api.github.com/repos/zenparsing/es-observable","labels_url":"https://api.github.com/repos/zenparsing/es-observable/issues/99/labels{/name}","comments_url":"https://api.github.com/repos/zenparsing/es-observable/issues/99/comments","events_url":"https://api.github.com/repos/zenparsing/es-observable/issues/99/events","html_url":"https://github.com/zenparsing/es-observable/issues/99","id":157678989,"number":99,"title":"Proposal: `subscribe` returns Cancellation Token","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":20,"created_at":"2016-05-31T14:00:45Z","updated_at":"2016-05-31T16:42:14Z","closed_at":null,"body":"Given what `Subscription` is, if we have cancellation tokens, there's no reason `Subscription` couldn't just be a cancellation token. My proposal is that we have `subscribe` take an optional cancellation token as a last argument, and also always return a cancellation token.\r\n\r\n\r\n```ts\r\ninterface Observable<T> {\r\n  subscribe(observer: Observer<T>, \r\n            token?: CancellationToken): CancellationToken\r\n  // or\r\n  subscribe(nextHandler?: (value: T) => void, \r\n            errorHandler?: (err: any) => void, \r\n            completeHandler?: (value: any) => void, \r\n            token? CancellationToken): CancellationToken\r\n}\r\n```\r\n\r\nThe idea is that if you don't have a cancellation token, one would be returned to you. I suspect this will be the 90% use case.\r\n\r\nHowever, if you do have a cancellation token you want the subscription to use, you can pass one to it as the optional last argument. That same cancellation token will be returned to you (I'm flexible on this), just for consistency.\r\n\r\nFor prior art, Most.js, I believe (@briancavalier can back me up here?), does this for internal calls to `run()` which is analogous to `subscribe()`.\r\n\r\nThe reasons I like this design:\r\n\r\n1. It's reusing a type that I think has a lot of potential and decreasing the API surface area as @domenic wanted.\r\n2. It doesn't fundementally change the semantics of Observable.\r\n3. I think this would be very useful in creating combinator chains that share a subscription, and or operators that have many inner subscriptions, like `flatMap`.\r\n4. If cancellation tokens are going to be ubiquitous for async in JavaScript, then subscription will be returning something useful, rather than something unique to the type.\r\n\r\nThe one thing I'd want to be sure of is that CancellationToken has some level of composability. For example, the ability to group other CancellationTokens together with an `add` and `remove` type functionality."},"comment":{"url":"https://api.github.com/repos/zenparsing/es-observable/issues/comments/222747315","html_url":"https://github.com/zenparsing/es-observable/issues/99#issuecomment-222747315","issue_url":"https://api.github.com/repos/zenparsing/es-observable/issues/99","id":222747315,"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-05-31T16:42:13Z","updated_at":"2016-05-31T16:42:13Z","body":"@staltz just rename `unsubscribe` to `cancel` and `Subscription` to `CancelationToken` - fun. "}}
{"actor":{"display_login":"benjamingr"}}