You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/example/mapreduce/irregular/irregular.go

29 lines
495 B
Go

4 years ago
package main
import (
"fmt"
"time"
"zero/core/mapreduce"
)
func main() {
mapreduce.MapReduceVoid(func(source chan<- interface{}) {
for i := 0; i < 10; i++ {
source <- i
}
}, func(item interface{}, writer mapreduce.Writer, cancel func(error)) {
i := item.(int)
if i == 0 {
time.Sleep(10 * time.Second)
} else {
time.Sleep(5 * time.Second)
}
writer.Write(i)
}, func(pipe <-chan interface{}, cancel func(error)) {
for i := range pipe {
fmt.Println(i)
}
})
}