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)
| 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. |
| 1789 | func (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. |
| 1826 | func (o *ObservableImpl) Run(opts ...Option) Disposed { |
nothing calls this directly
no test coverage detected