Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retryable feature. #9

Merged
merged 5 commits into from Dec 5, 2014
Merged

Add retryable feature. #9

merged 5 commits into from Dec 5, 2014

Conversation

inamiy
Copy link
Member

@inamiy inamiy commented Dec 4, 2014

This pull request brings a new retryable feature for future ver 2.1.0.

task.try(n) returns a new task that is retryable for n-1 times, and is conceptually equal to

task.failure(clonedTask1).failure(clonedTask2)...

with n-1 failure-able.

Usage

task.try(3).success { ...
    // this closure will be called even when task is rejected for 1st & 2nd try 
    // but fulfilled in 3rd try.
}

// shorthand
(task ~ 3).then { ... }

@inamiy
Copy link
Member Author

inamiy commented Dec 4, 2014

  • Test for progress, pause, cancel
  • Write README.md

Fix pause/cancel bug when chained with then/success/catch.
@inamiy
Copy link
Member Author

inamiy commented Dec 5, 2014

Ready to :shipit:

inamiy added a commit that referenced this pull request Dec 5, 2014
@inamiy inamiy merged commit 113dae4 into master Dec 5, 2014
@inamiy inamiy deleted the retryable branch December 5, 2014 14:07
@tspanindra
Copy link

Can i do task.try(3) after certain seconds? i mean can i introduce delay between each retry?

@inamiy
Copy link
Member Author

inamiy commented Aug 5, 2015

@panindra1
Unfortunately, no.
SwiftTask is not in charge of handling any timing controls.

Instead, you can implement on your own like this:

func taskWithDelay(delay: Float) -> Task<P, V, E> {
    return Task { ...
        dispatch_after(...) {
             // your task implementation here (after delay) 
        }
    }
}

// retry at most 1000 times, starting with delay=0 and then 3 sec each
taskWithDelay(0).failure { ... in taskWithDelay(3).try(1000-1) }

@tspanindra
Copy link

Wow..Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants