Retry this observable for the given number of times.
- Template Parameters
-
Count | the type of the counter (optional) |
- Parameters
-
t | the total number of tries (optional), i.e. retry(2) means one normal try, before an error occurs, and one retry. If not specified, infinitely retries the source observable. Specifying 0 returns immediately without subscribing |
- Returns
- An observable that mirrors the source observable, resubscribing to it if it calls on_error up to a specified number of retries.
- Sample Code
auto values = source.
retry(3);
values.
[](int v){printf("OnNext: %d\n", v);},
[](std::exception_ptr ep){
try {std::rethrow_exception(ep);}
catch (const std::exception& ex) {
printf("OnError: %s\n", ex.what());
}
},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 1
OnNext: 2
OnNext: 1
OnNext: 2
OnError: Error
from source