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

Function optionalSingle

observable.go:233–264  ·  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

231}
232
233func optionalSingle(parent context.Context, iterable Iterable, operatorFactory func() operator, forceSeq, bypassGather bool, opts ...Option) OptionalSingle {
234 option := parseOptions(opts...)
235 ctx := option.buildContext(parent)
236 parallel, _ := option.getPool()
237
238 if option.isEagerObservation() {
239 next := option.buildChannel()
240 if forceSeq || !parallel {
241 runSequential(ctx, next, iterable, operatorFactory, option, opts...)
242 } else {
243 runParallel(ctx, next, iterable.Observe(opts...), operatorFactory, bypassGather, option, opts...)
244 }
245 return &OptionalSingleImpl{iterable: newChannelIterable(next)}
246 }
247
248 return &OptionalSingleImpl{
249 parent: ctx,
250 iterable: newFactoryIterable(func(propagatedOptions ...Option) <-chan Item {
251 mergedOptions := append(opts, propagatedOptions...)
252 option = parseOptions(mergedOptions...)
253
254 next := option.buildChannel()
255 ctx := option.buildContext(parent)
256 if forceSeq || !parallel {
257 runSequential(ctx, next, iterable, operatorFactory, option, mergedOptions...)
258 } else {
259 runParallel(ctx, next, iterable.Observe(mergedOptions...), operatorFactory, bypassGather, option, mergedOptions...)
260 }
261 return next
262 }),
263 }
264}
265
266func runSequential(ctx context.Context, next chan Item, iterable Iterable, operatorFactory func() operator, option Option, opts ...Option) {
267 observe := iterable.Observe(opts...)

Callers 8

MapMethod · 0.85
FindMethod · 0.85
FirstMethod · 0.85
LastMethod · 0.85
MaxMethod · 0.85
MinMethod · 0.85
ReduceMethod · 0.85
FilterMethod · 0.85

Calls 10

parseOptionsFunction · 0.85
runSequentialFunction · 0.85
runParallelFunction · 0.85
newChannelIterableFunction · 0.85
newFactoryIterableFunction · 0.85
buildContextMethod · 0.65
getPoolMethod · 0.65
isEagerObservationMethod · 0.65
buildChannelMethod · 0.65
ObserveMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…