TimeInterval converts an Observable that emits items into one that emits indications of the amount of time elapsed between those emissions.
(opts ...Option)
| 2514 | |
| 2515 | // TimeInterval converts an Observable that emits items into one that emits indications of the amount of time elapsed between those emissions. |
| 2516 | func (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. |
| 2552 | func (o *ObservableImpl) Timestamp(opts ...Option) Observable { |
nothing calls this directly
no test coverage detected