{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang-nursery/wg-net/pulls/comments/236056524","pull_request_review_id":178065310,"id":236056524,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNjA1NjUyNA==","diff_hunk":"@@ -0,0 +1,104 @@\n+# The `Stream` Trait\n+\n+The `Stream` trait is similar to `Future` but can yield multiple values before\n+completing, similar to the `Iterator` trait from the standard library:\n+\n+```rust\n+trait Stream {\n+    /// The type of value yielded by the stream.\n+    type Item;\n+\n+    /// Attempt to resolve the next item in the stream.\n+    /// Returns `Poll::Pending` if not ready, `Poll::Ready(Some(x))` if a value\n+    /// is ready, and `Poll::Ready(None)` if the stream has completed.\n+    fn poll_next(self: Pin<&mut Self>, lw: &LocalWaker)\n+        -> Poll<Option<Self::Item>>;\n+}\n+```\n+\n+One common example of a `Stream` is the `Receiver` for the channel type from\n+the `futures` crate. It will yield `Some(val)` every time a value is sent\n+from the `Sender` end, and will yield `None` once the `Sender` has been\n+dropped and all pending messages have been received:\n+\n+```rust\n+use futures::channel::mpsc;\n+use futures::prelude::*;\n+\n+let fut = async {\n+    let (tx, rx) = mpsc::channel(BUFFER_SIZE);\n+    await!(tx.send(1)).unwrap();\n+    await!(tx.send(2)).unwrap();\n+    drop(tx);\n+\n+    // `StreamExt::next` is similar to `Iterator::next`, but returns a\n+    // type that implements `Future<Output = Option<T>>`.\n+    assert_eq!(Some(1), await!(rx.next()));\n+    assert_eq!(Some(2), await!(rx.next()));\n+    assert_eq!(None, await!(rx.next()));\n+};\n+```\n+\n+## Patterns: Iteration and Concurrency\n+\n+Similar to synchronous `Iterator`s, there are many different ways to iterate\n+over and process the values in a `Stream`. There are combinator-style methods\n+such as `map`, `filter`, and `fold`, and their early-exit-on-error cousins\n+`try_map`, `try_filter`, and `try_fold`.\n+\n+Unfortunately, `for` loops are not yet usable with `Stream`s, but for\n+imperative-style code, `while let` and `.for_each` are available:\n+\n+```rust\n+use futures::prelude::*;\n+\n+let fut = async {\n+    let mut stream: impl Stream<Item = Result<i32, io::Error>> = ...;\n+\n+    // processing with `try_for_each`:\n+    await!(stream.try_for_each(async |item| {\n+        // handle `item`\n+        Ok(())\n+    }))?;\n+\n+    // processing with `while let`:\n+    while let Some(item) = await!(stream.try_next())? {\n+        // handle `item`\n+    }\n+\n+    ...\n+\n+    Ok(())\n+};\n+```\n+\n+However, if we're just processing one element at a time, we're potentially\n+leaving behind opportunity for concurrency, which is, after all, why we're\n+writing async code in the first place. To process multiple items from a stream\n+concurrently, use the `for_each_concurrent` and `try_for_each_concurrent`\n+methods:\n+\n+```rust\n+use futures::prelude::*;\n+\n+let fut = async {\n+    let mut stream: impl Stream<Item = Result<i32, io::Error>> = ...;\n+\n+    await!(stream.try_for_each_concurrent(MAX_CONCURRENT_JUMPERS, async |num| {\n+        await!(jump_n_times(num))?;\n+        await!(report_jumps(num))?;","path":"async-book/src/streams/chapter.md","position":89,"original_position":89,"commit_id":"ce120b82be27234ae713cc6a026aa45a0c287a4e","original_commit_id":"ce120b82be27234ae713cc6a026aa45a0c287a4e","user":{"login":"yoshuawuyts","id":2467194,"node_id":"MDQ6VXNlcjI0NjcxOTQ=","avatar_url":"https://avatars3.githubusercontent.com/u/2467194?v=4","gravatar_id":"","url":"https://api.github.com/users/yoshuawuyts","html_url":"https://github.com/yoshuawuyts","followers_url":"https://api.github.com/users/yoshuawuyts/followers","following_url":"https://api.github.com/users/yoshuawuyts/following{/other_user}","gists_url":"https://api.github.com/users/yoshuawuyts/gists{/gist_id}","starred_url":"https://api.github.com/users/yoshuawuyts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yoshuawuyts/subscriptions","organizations_url":"https://api.github.com/users/yoshuawuyts/orgs","repos_url":"https://api.github.com/users/yoshuawuyts/repos","events_url":"https://api.github.com/users/yoshuawuyts/events{/privacy}","received_events_url":"https://api.github.com/users/yoshuawuyts/received_events","type":"User","site_admin":false},"body":"I found this part to be a bit confusing. Where does `jump_n_times` come from? Is that from `futures::prelude`, or is it some made up method?","created_at":"2018-11-24T23:42:56Z","updated_at":"2018-11-24T23:42:56Z","html_url":"https://github.com/rust-lang-nursery/wg-net/pull/73#discussion_r236056524","pull_request_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/pulls/73","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/rust-lang-nursery/wg-net/pulls/comments/236056524"},"html":{"href":"https://github.com/rust-lang-nursery/wg-net/pull/73#discussion_r236056524"},"pull_request":{"href":"https://api.github.com/repos/rust-lang-nursery/wg-net/pulls/73"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang-nursery/wg-net/pulls/73","id":231394991,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMxMzk0OTkx","html_url":"https://github.com/rust-lang-nursery/wg-net/pull/73","diff_url":"https://github.com/rust-lang-nursery/wg-net/pull/73.diff","patch_url":"https://github.com/rust-lang-nursery/wg-net/pull/73.patch","issue_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/issues/73","number":73,"state":"open","locked":false,"title":"[book] Add section introducing Streams","user":{"login":"cramertj","id":5963049,"node_id":"MDQ6VXNlcjU5NjMwNDk=","avatar_url":"https://avatars1.githubusercontent.com/u/5963049?v=4","gravatar_id":"","url":"https://api.github.com/users/cramertj","html_url":"https://github.com/cramertj","followers_url":"https://api.github.com/users/cramertj/followers","following_url":"https://api.github.com/users/cramertj/following{/other_user}","gists_url":"https://api.github.com/users/cramertj/gists{/gist_id}","starred_url":"https://api.github.com/users/cramertj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cramertj/subscriptions","organizations_url":"https://api.github.com/users/cramertj/orgs","repos_url":"https://api.github.com/users/cramertj/repos","events_url":"https://api.github.com/users/cramertj/events{/privacy}","received_events_url":"https://api.github.com/users/cramertj/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-11-16T02:14:07Z","updated_at":"2018-11-24T23:42:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c8ae90c80a203a3e6308ce39365d40e12534ea02","assignee":null,"assignees":[],"requested_reviewers":[{"login":"aturon","id":709807,"node_id":"MDQ6VXNlcjcwOTgwNw==","avatar_url":"https://avatars2.githubusercontent.com/u/709807?v=4","gravatar_id":"","url":"https://api.github.com/users/aturon","html_url":"https://github.com/aturon","followers_url":"https://api.github.com/users/aturon/followers","following_url":"https://api.github.com/users/aturon/following{/other_user}","gists_url":"https://api.github.com/users/aturon/gists{/gist_id}","starred_url":"https://api.github.com/users/aturon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aturon/subscriptions","organizations_url":"https://api.github.com/users/aturon/orgs","repos_url":"https://api.github.com/users/aturon/repos","events_url":"https://api.github.com/users/aturon/events{/privacy}","received_events_url":"https://api.github.com/users/aturon/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/pulls/73/commits","review_comments_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/pulls/73/comments","review_comment_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/issues/73/comments","statuses_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/statuses/ce120b82be27234ae713cc6a026aa45a0c287a4e","head":{"label":"cramertj:book-more","ref":"book-more","sha":"ce120b82be27234ae713cc6a026aa45a0c287a4e","user":{"login":"cramertj","id":5963049,"node_id":"MDQ6VXNlcjU5NjMwNDk=","avatar_url":"https://avatars1.githubusercontent.com/u/5963049?v=4","gravatar_id":"","url":"https://api.github.com/users/cramertj","html_url":"https://github.com/cramertj","followers_url":"https://api.github.com/users/cramertj/followers","following_url":"https://api.github.com/users/cramertj/following{/other_user}","gists_url":"https://api.github.com/users/cramertj/gists{/gist_id}","starred_url":"https://api.github.com/users/cramertj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cramertj/subscriptions","organizations_url":"https://api.github.com/users/cramertj/orgs","repos_url":"https://api.github.com/users/cramertj/repos","events_url":"https://api.github.com/users/cramertj/events{/privacy}","received_events_url":"https://api.github.com/users/cramertj/received_events","type":"User","site_admin":false},"repo":{"id":148199451,"node_id":"MDEwOlJlcG9zaXRvcnkxNDgxOTk0NTE=","name":"wg-net","full_name":"cramertj/wg-net","private":false,"owner":{"login":"cramertj","id":5963049,"node_id":"MDQ6VXNlcjU5NjMwNDk=","avatar_url":"https://avatars1.githubusercontent.com/u/5963049?v=4","gravatar_id":"","url":"https://api.github.com/users/cramertj","html_url":"https://github.com/cramertj","followers_url":"https://api.github.com/users/cramertj/followers","following_url":"https://api.github.com/users/cramertj/following{/other_user}","gists_url":"https://api.github.com/users/cramertj/gists{/gist_id}","starred_url":"https://api.github.com/users/cramertj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cramertj/subscriptions","organizations_url":"https://api.github.com/users/cramertj/orgs","repos_url":"https://api.github.com/users/cramertj/repos","events_url":"https://api.github.com/users/cramertj/events{/privacy}","received_events_url":"https://api.github.com/users/cramertj/received_events","type":"User","site_admin":false},"html_url":"https://github.com/cramertj/wg-net","description":"Rust 2018 Networking Working Group","fork":true,"url":"https://api.github.com/repos/cramertj/wg-net","forks_url":"https://api.github.com/repos/cramertj/wg-net/forks","keys_url":"https://api.github.com/repos/cramertj/wg-net/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cramertj/wg-net/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cramertj/wg-net/teams","hooks_url":"https://api.github.com/repos/cramertj/wg-net/hooks","issue_events_url":"https://api.github.com/repos/cramertj/wg-net/issues/events{/number}","events_url":"https://api.github.com/repos/cramertj/wg-net/events","assignees_url":"https://api.github.com/repos/cramertj/wg-net/assignees{/user}","branches_url":"https://api.github.com/repos/cramertj/wg-net/branches{/branch}","tags_url":"https://api.github.com/repos/cramertj/wg-net/tags","blobs_url":"https://api.github.com/repos/cramertj/wg-net/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cramertj/wg-net/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cramertj/wg-net/git/refs{/sha}","trees_url":"https://api.github.com/repos/cramertj/wg-net/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cramertj/wg-net/statuses/{sha}","languages_url":"https://api.github.com/repos/cramertj/wg-net/languages","stargazers_url":"https://api.github.com/repos/cramertj/wg-net/stargazers","contributors_url":"https://api.github.com/repos/cramertj/wg-net/contributors","subscribers_url":"https://api.github.com/repos/cramertj/wg-net/subscribers","subscription_url":"https://api.github.com/repos/cramertj/wg-net/subscription","commits_url":"https://api.github.com/repos/cramertj/wg-net/commits{/sha}","git_commits_url":"https://api.github.com/repos/cramertj/wg-net/git/commits{/sha}","comments_url":"https://api.github.com/repos/cramertj/wg-net/comments{/number}","issue_comment_url":"https://api.github.com/repos/cramertj/wg-net/issues/comments{/number}","contents_url":"https://api.github.com/repos/cramertj/wg-net/contents/{+path}","compare_url":"https://api.github.com/repos/cramertj/wg-net/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cramertj/wg-net/merges","archive_url":"https://api.github.com/repos/cramertj/wg-net/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cramertj/wg-net/downloads","issues_url":"https://api.github.com/repos/cramertj/wg-net/issues{/number}","pulls_url":"https://api.github.com/repos/cramertj/wg-net/pulls{/number}","milestones_url":"https://api.github.com/repos/cramertj/wg-net/milestones{/number}","notifications_url":"https://api.github.com/repos/cramertj/wg-net/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cramertj/wg-net/labels{/name}","releases_url":"https://api.github.com/repos/cramertj/wg-net/releases{/id}","deployments_url":"https://api.github.com/repos/cramertj/wg-net/deployments","created_at":"2018-09-10T18:20:56Z","updated_at":"2018-11-19T02:06:20Z","pushed_at":"2018-11-21T20:55:20Z","git_url":"git://github.com/cramertj/wg-net.git","ssh_url":"git@github.com:cramertj/wg-net.git","clone_url":"https://github.com/cramertj/wg-net.git","svn_url":"https://github.com/cramertj/wg-net","homepage":"https://rust-lang-nursery.github.io/wg-net/","size":2917,"stargazers_count":3,"watchers_count":3,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":3,"default_branch":"master"}},"base":{"label":"rust-lang-nursery:master","ref":"master","sha":"1e4fb0256697e1633aa2803416eb690246452ef1","user":{"login":"rust-lang-nursery","id":14631425,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE0NjMxNDI1","avatar_url":"https://avatars1.githubusercontent.com/u/14631425?v=4","gravatar_id":"","url":"https://api.github.com/users/rust-lang-nursery","html_url":"https://github.com/rust-lang-nursery","followers_url":"https://api.github.com/users/rust-lang-nursery/followers","following_url":"https://api.github.com/users/rust-lang-nursery/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang-nursery/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang-nursery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang-nursery/subscriptions","organizations_url":"https://api.github.com/users/rust-lang-nursery/orgs","repos_url":"https://api.github.com/users/rust-lang-nursery/repos","events_url":"https://api.github.com/users/rust-lang-nursery/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang-nursery/received_events","type":"Organization","site_admin":false},"repo":{"id":130051909,"node_id":"MDEwOlJlcG9zaXRvcnkxMzAwNTE5MDk=","name":"wg-net","full_name":"rust-lang-nursery/wg-net","private":false,"owner":{"login":"rust-lang-nursery","id":14631425,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE0NjMxNDI1","avatar_url":"https://avatars1.githubusercontent.com/u/14631425?v=4","gravatar_id":"","url":"https://api.github.com/users/rust-lang-nursery","html_url":"https://github.com/rust-lang-nursery","followers_url":"https://api.github.com/users/rust-lang-nursery/followers","following_url":"https://api.github.com/users/rust-lang-nursery/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang-nursery/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang-nursery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang-nursery/subscriptions","organizations_url":"https://api.github.com/users/rust-lang-nursery/orgs","repos_url":"https://api.github.com/users/rust-lang-nursery/repos","events_url":"https://api.github.com/users/rust-lang-nursery/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang-nursery/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/rust-lang-nursery/wg-net","description":"Rust 2018 Networking Working Group","fork":false,"url":"https://api.github.com/repos/rust-lang-nursery/wg-net","forks_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/forks","keys_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/teams","hooks_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/hooks","issue_events_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/events","assignees_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/tags","blobs_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/languages","stargazers_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/stargazers","contributors_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/contributors","subscribers_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/subscribers","subscription_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/subscription","commits_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/merges","archive_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/downloads","issues_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/releases{/id}","deployments_url":"https://api.github.com/repos/rust-lang-nursery/wg-net/deployments","created_at":"2018-04-18T11:27:25Z","updated_at":"2018-11-19T15:20:45Z","pushed_at":"2018-11-21T20:55:21Z","git_url":"git://github.com/rust-lang-nursery/wg-net.git","ssh_url":"git@github.com:rust-lang-nursery/wg-net.git","clone_url":"https://github.com/rust-lang-nursery/wg-net.git","svn_url":"https://github.com/rust-lang-nursery/wg-net","homepage":"https://rust-lang-nursery.github.io/wg-net/","size":2940,"stargazers_count":171,"watchers_count":171,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":16,"mirror_url":null,"archived":false,"open_issues_count":39,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":16,"open_issues":39,"watchers":171,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang-nursery/wg-net/pulls/73"},"html":{"href":"https://github.com/rust-lang-nursery/wg-net/pull/73"},"issue":{"href":"https://api.github.com/repos/rust-lang-nursery/wg-net/issues/73"},"comments":{"href":"https://api.github.com/repos/rust-lang-nursery/wg-net/issues/73/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang-nursery/wg-net/pulls/73/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang-nursery/wg-net/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-lang-nursery/wg-net/pulls/73/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang-nursery/wg-net/statuses/ce120b82be27234ae713cc6a026aa45a0c287a4e"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"yoshuawuyts"}}