go-zero/example/mapreduce/irregular/irregular.go

29 lines
474 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package main
import (
"fmt"
"time"
2020-07-29 22:34:37 +08:00
"zero/core/mr"
2020-07-26 17:09:05 +08:00
)
func main() {
2020-07-29 22:34:37 +08:00
mr.MapReduceVoid(func(source chan<- interface{}) {
2020-07-26 17:09:05 +08:00
for i := 0; i < 10; i++ {
source <- i
}
2020-07-29 22:34:37 +08:00
}, func(item interface{}, writer mr.Writer, cancel func(error)) {
2020-07-26 17:09:05 +08:00
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)
}
})
}