Typhoon
是一个用于重试策略的服务。
Typhoon
提供了三种重试策略
/// A retry strategy with a constant number of attempts and fixed duration between retries.
case constant(retry: Int, duration: DispatchTimeInterval)
/// A retry strategy with an exponential increase in duration between retries.
case exponential(retry: Int, multiplier: Double = 2.0, duration: DispatchTimeInterval)
/// A retry strategy with exponential increase in duration between retries and added jitter.
case exponentialWithJitter(retry: Int, jitterFactor: Double = 0.1, maxInterval: UInt64? = 60, multiplier: Double = 2.0, duration: DispatchTimeInterval)
创建一个 RetryPolicyService
实例并像这样传递所需的策略
import Typhoon
let retryPolicyService = RetryPolicyService(strategy: .constant(retry: 10, duration: .seconds(1)))
do {
_ = try await retryPolicyService.retry {
// Some logic here ...
}
} catch {
// Catch an error here ...
}
Swift Package Manager 是一个用于自动化 Swift 代码分发的工具,并集成到了 swift
编译器中。它尚处于早期开发阶段,但是 typhoon
确实支持在受支持的平台上使用它。
一旦你设置好了你的 Swift 包,添加 typhoon
作为依赖项就像将其添加到你的 Package.swift
文件的 dependencies
值中一样容易。
dependencies: [
.package(url: "https://github.com/space-code/typhoon.git", .upToNextMajor(from: "1.0.0"))
]
引导开发环境
make bootstrap
请随时帮助改进这个项目!如果你看到任何可以改进的地方或者想要新功能,请提交 issue 或发送 Pull Request!
Nikita Vasilev, nv3212@gmail.com
typhoon 基于 MIT 许可证发布。有关更多信息,请参阅 LICENSE 文件。