MCPcopy Create free account
hub / github.com/ReactiveX/RxGo / observable

Function observable

observable.go:130–201  ·  view source on GitHub ↗
(parent context.Context, iterable Iterable, operatorFactory func() operator, forceSeq, bypassGather bool, opts ...Option)

Source from the content-addressed store, hash-verified

128}
129
130func observable(parent context.Context, iterable Iterable, operatorFactory func() operator, forceSeq, bypassGather bool, opts ...Option) Observable {
131 option := parseOptions(opts...)
132 parallel, _ := option.getPool()
133
134 if option.isEagerObservation() {
135 next := option.buildChannel()
136 ctx := option.buildContext(parent)
137 if forceSeq || !parallel {
138 runSequential(ctx, next, iterable, operatorFactory, option, opts...)
139 } else {
140 runParallel(ctx, next, iterable.Observe(opts...), operatorFactory, bypassGather, option, opts...)
141 }
142 return &ObservableImpl{iterable: newChannelIterable(next)}
143 }
144
145 if forceSeq || !parallel {
146 return &ObservableImpl{
147 iterable: newFactoryIterable(func(propagatedOptions ...Option) <-chan Item {
148 mergedOptions := append(opts, propagatedOptions...)
149 option := parseOptions(mergedOptions...)
150
151 next := option.buildChannel()
152 ctx := option.buildContext(parent)
153 runSequential(ctx, next, iterable, operatorFactory, option, mergedOptions...)
154 return next
155 }),
156 }
157 }
158
159 if serialized, f := option.isSerialized(); serialized {
160 firstItemIDCh := make(chan Item, 1)
161 fromCh := make(chan Item, 1)
162 obs := &ObservableImpl{
163 iterable: newFactoryIterable(func(propagatedOptions ...Option) <-chan Item {
164 mergedOptions := append(opts, propagatedOptions...)
165 option := parseOptions(mergedOptions...)
166
167 next := option.buildChannel()
168 ctx := option.buildContext(parent)
169 observe := iterable.Observe(opts...)
170 go func() {
171 select {
172 case <-ctx.Done():
173 return
174 case firstItemID := <-firstItemIDCh:
175 if firstItemID.Error() {
176 firstItemID.SendContext(ctx, fromCh)
177 return
178 }
179 Of(firstItemID.V.(int)).SendContext(ctx, fromCh)
180 runParallel(ctx, next, observe, operatorFactory, bypassGather, option, mergedOptions...)
181 }
182 }()
183 runFirstItem(ctx, f, firstItemIDCh, observe, next, operatorFactory, option, mergedOptions...)
184 return next
185 }),
186 }
187 return obs.serialize(parent, fromCh, f)

Callers 15

BufferWithCountMethod · 0.85
DefaultIfEmptyMethod · 0.85
DistinctMethod · 0.85
DistinctUntilChangedMethod · 0.85
FilterMethod · 0.85
IgnoreElementsMethod · 0.85
MapMethod · 0.85
OnErrorResumeNextMethod · 0.85
OnErrorReturnMethod · 0.85
OnErrorReturnItemMethod · 0.85
RepeatMethod · 0.85
ScanMethod · 0.85

Calls 15

serializeMethod · 0.95
parseOptionsFunction · 0.85
runSequentialFunction · 0.85
runParallelFunction · 0.85
newChannelIterableFunction · 0.85
newFactoryIterableFunction · 0.85
OfFunction · 0.85
runFirstItemFunction · 0.85
SendContextMethod · 0.80
getPoolMethod · 0.65
isEagerObservationMethod · 0.65
buildChannelMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…