RxGo icon indicating copy to clipboard operation
RxGo copied to clipboard

In GroupByDynamic example,when I set count to 100,the program will be blocked

Open kdchelsea opened this issue 4 years ago • 1 comments

In GroupByDynamic example,when I set count to 100,the program will be blocked,just print part of result my go version is go1.15.10 darwin/amd64,rxgo version is 2.5.0

image

kdchelsea avatar Jun 30 '21 09:06 kdchelsea

in current example, new group observable isn't be consumed ASAP. so it block when one group observable buffer full. we should modify the example

func main() {
	count := 3
	observable := rxgo.Range(0, 100).GroupByDynamic(func(item rxgo.Item) string {
		return strconv.Itoa(item.V.(int) % count)
	})

	disposeds := make([]rxgo.Disposed, 0)
	for i := range observable.Observe() {
		groupedObservable := i.V.(rxgo.GroupedObservable)
		fmt.Printf("New observable: %s\n", groupedObservable.Key)

		disposeds = append(disposeds, groupedObservable.DoOnNext(func(i interface{}) {
			fmt.Printf("item: %v\n", i)
		}))
	}
	for _, disposed := range disposeds {
		<-disposed
	}
}

okhowang avatar May 18 '22 05:05 okhowang