Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "5. Concurrency at Scale" more complicated ward sample #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,34 +110,55 @@ func main() {
}()
return takeStream
}
//bridge := func(
// done <-chan interface{},
// chanStream <-chan <-chan interface{},
//) <-chan interface{} {
// valStream := make(chan interface{}) // <1>
// go func() {
// defer close(valStream)
// for { // <2>
// var stream <-chan interface{}
// select {
// case maybeStream, ok := <-chanStream:
// if ok == false {
// return
// }
// stream = maybeStream
// case <-done:
// return
// }
// for val := range orDone(done, stream) { // <3>
// select {
// case valStream <- val:
// case <-done:
// }
// }
// }
// }()
// return valStream
//}
orDone := func(done, c <-chan interface{}) <-chan interface{} {
valStream := make(chan interface{})
go func() {
defer close(valStream)
for {
select {
case <-done:
return
case v, ok := <-c:
if ok == false {
return
}
select {
case valStream <- v:
case <-done:
}
}
}
}()
return valStream
}
bridge := func(
done <-chan interface{},
chanStream <-chan <-chan interface{},
) <-chan interface{} {
valStream := make(chan interface{}) // <1>
go func() {
defer close(valStream)
for { // <2>
var stream <-chan interface{}
select {
case maybeStream, ok := <-chanStream:
if ok == false {
return
}
stream = maybeStream
case <-done:
return
}
for val := range orDone(done, stream) { // <3>
select {
case valStream <- val:
case <-done:
}
}
}
}()
return valStream
}
doWorkFn := func(
done <-chan interface{},
intList ...int,
Expand Down