ConstraintRunner is a Swift library allowing you to perform async operations once in a while. A task (an asynchronous operation can be constrained by time or by a precise network conditon.
API inspired by https://github.com/luoxiu/Schedule
Some basic usage, here someAsyncJob
will be executed at most once a day when the network is reachable. If the task fails, it will be allowed to retry every 10 seconds.
import ConstraintRunner
let runner = ConstraintRunner(identifier: "runner-id")
.period(.onceADay)
.connectivity(atLeast: .reachable)
.maxRetryInterval(10_000)
// didRun indicates if your job have been started or not
let didRun = runner.runIfNeeded { handler in
someAsyncJob { error in
// True if the task succeeded
// False if it failed
handler(error == nil)
}
}
Synchronous job
let didRun = runner.runIfNeeded {
return someSyncJob()
}
Force job execution
runner.runIfNeeded(force: true) { ... }
Utility methods
runner.shouldRun()
runner.didLastExecutionFail()
link |
Stars: 0 |
Last commit: 3 years ago |
Fix public declaration
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics