+ (AnyPromise *) retry:(int)count delay:(NSTimeInterval)delay block:(AnyPromise *(^)(void))block {
AnyPromise* (^attemp)(void) = ^AnyPromise*() {
return block().catch(^(NSError *error) {
if(count <= 1) {
@throw error;
}
return PMKAfter(delay).then(^{
return [AnyPromise retry:count-1 delay:delay block:block];
});
});
};
return attemp();
}
Usage:
[AnyPromise retry:2 delay:1 block:^AnyPromise *{
// Code that returns a AnyPromise object
......
}];