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

Method TimeInterval

observable_operator.go:2516–2549  ·  view source on GitHub ↗

TimeInterval converts an Observable that emits items into one that emits indications of the amount of time elapsed between those emissions.

(opts ...Option)

Source from the content-addressed store, hash-verified

2514
2515// TimeInterval converts an Observable that emits items into one that emits indications of the amount of time elapsed between those emissions.
2516func (o *ObservableImpl) TimeInterval(opts ...Option) Observable {
2517 f := func(ctx context.Context, next chan Item, option Option, opts ...Option) {
2518 defer close(next)
2519 observe := o.Observe(opts...)
2520 latest := time.Now().UTC()
2521
2522 for {
2523 select {
2524 case <-ctx.Done():
2525 return
2526 case item, ok := <-observe:
2527 if !ok {
2528 return
2529 }
2530 if item.Error() {
2531 if !item.SendContext(ctx, next) {
2532 return
2533 }
2534 if option.getErrorStrategy() == StopOnError {
2535 return
2536 }
2537 } else {
2538 now := time.Now().UTC()
2539 if !Of(now.Sub(latest)).SendContext(ctx, next) {
2540 return
2541 }
2542 latest = now
2543 }
2544 }
2545 }
2546 }
2547
2548 return customObservableOperator(o.parent, f, opts...)
2549}
2550
2551// Timestamp attaches a timestamp to each item emitted by an Observable indicating when it was emitted.
2552func (o *ObservableImpl) Timestamp(opts ...Option) Observable {

Callers

nothing calls this directly

Calls 6

ObserveMethod · 0.95
OfFunction · 0.85
customObservableOperatorFunction · 0.85
SendContextMethod · 0.80
ErrorMethod · 0.65
getErrorStrategyMethod · 0.65

Tested by

no test coverage detected