{"action":"created","issue":{"url":"https://api.github.com/repos/alexcrichton/futures-rs/issues/611","repository_url":"https://api.github.com/repos/alexcrichton/futures-rs","labels_url":"https://api.github.com/repos/alexcrichton/futures-rs/issues/611/labels{/name}","comments_url":"https://api.github.com/repos/alexcrichton/futures-rs/issues/611/comments","events_url":"https://api.github.com/repos/alexcrichton/futures-rs/issues/611/events","html_url":"https://github.com/alexcrichton/futures-rs/issues/611","id":265142523,"number":611,"title":"Can stream/sink be extended to become observable/observer?","user":{"login":"3n-mb","id":13634613,"avatar_url":"https://avatars1.githubusercontent.com/u/13634613?v=4","gravatar_id":"","url":"https://api.github.com/users/3n-mb","html_url":"https://github.com/3n-mb","followers_url":"https://api.github.com/users/3n-mb/followers","following_url":"https://api.github.com/users/3n-mb/following{/other_user}","gists_url":"https://api.github.com/users/3n-mb/gists{/gist_id}","starred_url":"https://api.github.com/users/3n-mb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/3n-mb/subscriptions","organizations_url":"https://api.github.com/users/3n-mb/orgs","repos_url":"https://api.github.com/users/3n-mb/repos","events_url":"https://api.github.com/users/3n-mb/events{/privacy}","received_events_url":"https://api.github.com/users/3n-mb/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2017-10-13T01:36:00Z","updated_at":"2017-10-17T19:58:29Z","closed_at":"2017-10-17T19:58:29Z","author_association":"NONE","body":"#### Context\r\nAPI for stream, with likes of `map`, `take`, `filter` all looks and smells like operators of observables. And if one wants to create library with observables, rust style, it seems that this may be a good start. Futures are here already. And futures (promises) are a special case of observables.\r\n\r\n[Docs](https://tokio.rs/docs/getting-started/streams-and-sinks/#concurrency) do say something about concurrency, sort of hinting that current implementation of streams cannot be directly used as rust's observables pattern.\r\n\r\n#### Why observables?\r\nIt has been noticed that casting program's logical processes with observables helps developer to articulate quite complex processes in a readable/digestible code.\r\n\r\nIncoming data is one type of events. Another type of events are mere signals between/inside processes. Events are treated as a first order objects, while observables (streams, where events flow) are second order objects. Clean separation of a second order abstract layer allows it to be used for process-shaping code, i.e. operators like `map`, `take`, `debounce` etc.\r\n\r\nEach chain of observables is a logical process, a sequence of particular actions, setup in a particular order. When a cold observable is subscribed to, it becomes an active process.\r\nThis is a very clean and useful abstraction.\r\n\r\n#### Desired thing: observables, rust style\r\nWhen writing processes in observables, one shouldn't explicitly use threads. Instead, operators should provide for parallel execution were needed.\r\nOf cause, rust's types naturally protect against common errors with parallelism, hence, a strong believe that observable style library will fit right with rust.\r\n*Side note: I prefer name stream to observable and name sink to observer*.\r\n\r\nCase 1.\r\nWhen an operation in a section of observables is heavy (or blocking a thread), we may want to have such section run in parallel, in some thread pool.\r\n\r\nCase 2.\r\nWhen there are few adjacent operators that are light, and non-blocking, non-futuring, we may want to run such section in exactly one thread. Potential switch of threads between tiny operations just adds an overhead, hence this case is needed in an efficiency-promising language :smile: \r\n\r\nCase 2a.\r\nSections from case 2 may also be run in parallel. Similarly to how parallelism is introduced in [mentioned docs](https://tokio.rs/docs/getting-started/streams-and-sinks/#concurrency) for streams.\r\n\r\nCase 3.\r\nIn sections that run in one thread, we may want to have operations that return future, and that future is flattened. Say, in a chain `stream.op1().op2(). ...`, if `op5` is a `flatMap` and produces a future, that is not resolved yet, an executor may start processing events that are ready, like new event at `op1`.\r\nIs this the case with current stream?\r\n\r\n#### Questions:\r\n - How easy is it to make streams for case 1?\r\n - What do you think about having case 2, not only case 1? Bonus here is that current streams may already be implementing this, sort of.\r\n - How far current streams from case 3? Or, are streams mere analog of pipelines, like  ones used in jetty for processing incoming data? I.e. how far streams are from observables, at least is a case of one thread."},"comment":{"url":"https://api.github.com/repos/alexcrichton/futures-rs/issues/comments/337351903","html_url":"https://github.com/alexcrichton/futures-rs/issues/611#issuecomment-337351903","issue_url":"https://api.github.com/repos/alexcrichton/futures-rs/issues/611","id":337351903,"user":{"login":"3n-mb","id":13634613,"avatar_url":"https://avatars1.githubusercontent.com/u/13634613?v=4","gravatar_id":"","url":"https://api.github.com/users/3n-mb","html_url":"https://github.com/3n-mb","followers_url":"https://api.github.com/users/3n-mb/followers","following_url":"https://api.github.com/users/3n-mb/following{/other_user}","gists_url":"https://api.github.com/users/3n-mb/gists{/gist_id}","starred_url":"https://api.github.com/users/3n-mb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/3n-mb/subscriptions","organizations_url":"https://api.github.com/users/3n-mb/orgs","repos_url":"https://api.github.com/users/3n-mb/repos","events_url":"https://api.github.com/users/3n-mb/events{/privacy}","received_events_url":"https://api.github.com/users/3n-mb/received_events","type":"User","site_admin":false},"created_at":"2017-10-17T19:58:28Z","updated_at":"2017-10-17T19:58:28Z","author_association":"NONE","body":"@tailhook this is cool :+1: All parts for Observables are here."}}
{"actor":{"display_login":"3n-mb"}}