Skip to content

Commit e8a0edc

Browse files
committed
fix: issue ReactiveX#341
1 parent 7d96f8e commit e8a0edc

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

item.go

+33
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,39 @@ func send(ctx context.Context, ch chan<- Item, items ...interface{}) {
8484
}
8585
}
8686

87+
func sendSingleItem(ctx context.Context, ch chan<- Item, strategy CloseChannelStrategy, items ...interface{}) {
88+
if strategy == CloseChannel {
89+
defer close(ch)
90+
}
91+
for _, currentItem := range items {
92+
switch item := currentItem.(type) {
93+
default:
94+
rt := reflect.TypeOf(item)
95+
switch rt.Kind() {
96+
default:
97+
Of(item).SendContext(ctx, ch)
98+
case reflect.Chan:
99+
in := reflect.ValueOf(currentItem)
100+
for {
101+
v, ok := in.Recv()
102+
if !ok {
103+
return
104+
}
105+
currentItem := v.Interface()
106+
switch item := currentItem.(type) {
107+
default:
108+
Of(item).SendContext(ctx, ch)
109+
case error:
110+
Error(item).SendContext(ctx, ch)
111+
}
112+
}
113+
}
114+
case error:
115+
Error(item).SendContext(ctx, ch)
116+
}
117+
}
118+
}
119+
87120
// Error checks if an item is an error.
88121
func (i Item) Error() bool {
89122
return i.E != nil

iterable_just.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ func (i *justIterable) Observe(opts ...Option) <-chan Item {
1818
option := parseOptions(append(i.opts, opts...)...)
1919
next := option.buildChannel()
2020

21-
go SendItems(option.buildContext(emptyContext), next, CloseChannel, i.items)
21+
go sendSingleItem(option.buildContext(emptyContext), next, CloseChannel, i.items...)
2222
return next
2323
}

single.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package rxgo
22

3-
import "context"
3+
import (
4+
"context"
5+
)
46

57
// Single is a observable with a single element.
68
type Single interface {

0 commit comments

Comments
 (0)