Kevin Wan 4 years ago committed by GitHub
parent 14cecb9b31
commit a87978568a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -136,14 +136,16 @@ func MapReduceWithSource(source <-chan interface{}, mapper MapperFunc, reducer R
go func() { go func() {
defer func() { defer func() {
drain(collector)
if r := recover(); r != nil { if r := recover(); r != nil {
cancel(fmt.Errorf("%v", r)) cancel(fmt.Errorf("%v", r))
} else { } else {
finish() finish()
} }
}() }()
reducer(collector, writer, cancel) reducer(collector, writer, cancel)
drain(collector)
}() }()
go executeMappers(func(item interface{}, w Writer) { go executeMappers(func(item interface{}, w Writer) {
@ -165,7 +167,6 @@ func MapReduceWithSource(source <-chan interface{}, mapper MapperFunc, reducer R
func MapReduceVoid(generate GenerateFunc, mapper MapperFunc, reducer VoidReducerFunc, opts ...Option) error { func MapReduceVoid(generate GenerateFunc, mapper MapperFunc, reducer VoidReducerFunc, opts ...Option) error {
_, err := MapReduce(generate, mapper, func(input <-chan interface{}, writer Writer, cancel func(error)) { _, err := MapReduce(generate, mapper, func(input <-chan interface{}, writer Writer, cancel func(error)) {
reducer(input, cancel) reducer(input, cancel)
drain(input)
// We need to write a placeholder to let MapReduce to continue on reducer done, // We need to write a placeholder to let MapReduce to continue on reducer done,
// otherwise, all goroutines are waiting. The placeholder will be discarded by MapReduce. // otherwise, all goroutines are waiting. The placeholder will be discarded by MapReduce.
writer.Write(lang.Placeholder) writer.Write(lang.Placeholder)

Loading…
Cancel
Save