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

Method Retry

observable_operator.go:1789–1823  ·  view source on GitHub ↗

Retry retries if a source Observable sends an error, resubscribe to it in the hopes that it will complete without error. Cannot be run in parallel.

(count int, shouldRetry func(error) bool, opts ...Option)

Source from the content-addressed store, hash-verified

1787// Retry retries if a source Observable sends an error, resubscribe to it in the hopes that it will complete without error.
1788// Cannot be run in parallel.
1789func (o *ObservableImpl) Retry(count int, shouldRetry func(error) bool, opts ...Option) Observable {
1790 option := parseOptions(opts...)
1791 next := option.buildChannel()
1792 ctx := option.buildContext(o.parent)
1793
1794 go func() {
1795 observe := o.Observe(opts...)
1796 loop:
1797 for {
1798 select {
1799 case <-ctx.Done():
1800 break loop
1801 case i, ok := <-observe:
1802 if !ok {
1803 break loop
1804 }
1805 if i.Error() {
1806 count--
1807 if count < 0 || !shouldRetry(i.E) {
1808 i.SendContext(ctx, next)
1809 break loop
1810 }
1811 observe = o.Observe(opts...)
1812 } else {
1813 i.SendContext(ctx, next)
1814 }
1815 }
1816 }
1817 close(next)
1818 }()
1819
1820 return &ObservableImpl{
1821 iterable: newChannelIterable(next),
1822 }
1823}
1824
1825// Run creates an Observer without consuming the emitted items.
1826func (o *ObservableImpl) Run(opts ...Option) Disposed {

Callers

nothing calls this directly

Calls 7

ObserveMethod · 0.95
parseOptionsFunction · 0.85
newChannelIterableFunction · 0.85
SendContextMethod · 0.80
buildChannelMethod · 0.65
buildContextMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected