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
497 B
Go

4 years ago
package main
import (
"fmt"
"time"
"github.com/tal-tech/go-zero/core/mr"
4 years ago
)
func main() {
mr.MapReduceVoid(func(source chan<- interface{}) {
4 years ago
for i := 0; i < 10; i++ {
source <- i
}
}, func(item interface{}, writer mr.Writer, cancel func(error)) {
4 years ago
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)
}
})
}