Swiftpack.co - Drusy/ConstraintRunner as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Drusy.
Drusy/ConstraintRunner 1.0.1
Task runner constraints in Swift
⭐️ 0
🕓 3 years ago
iOS
.package(url: "https://github.com/Drusy/ConstraintRunner.git", from: "1.0.1")

ConstraintRunner

Swift Package Manager Compatible MIT Lience

About

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

How to use

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()

GitHub

link
Stars: 0
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Public Starter
3 years ago

Fix public declaration

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics