https://github.com/flowerinthenight/zbackoff
Jittered backoff implementation in Zig.
https://github.com/flowerinthenight/zbackoff
backoff jitter retry zig ziglang
Last synced: 8 months ago
JSON representation
Jittered backoff implementation in Zig.
- Host: GitHub
- URL: https://github.com/flowerinthenight/zbackoff
- Owner: flowerinthenight
- License: mit
- Created: 2024-07-24T06:55:11.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-18T18:00:57.000Z (about 1 year ago)
- Last Synced: 2025-04-09T02:35:57.406Z (about 1 year ago)
- Topics: backoff, jitter, retry, zig, ziglang
- Language: Zig
- Homepage:
- Size: 35.2 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/flowerinthenight/zbackoff/actions/workflows/main.yml)
(This repo is mirrored to [https://codeberg.org/flowerinthenight/zbackoff](https://codeberg.org/flowerinthenight/zbackoff)).
**zbackoff** implements jittered backoff. Useful when retrying operations that can potentially fail (i.e. network calls). The implementation is based on [this article](https://www.awsarchitectureblog.com/2015/03/backoff.html) from the AWS Architecture Blog.
You can use it like so:
``` zig
const std = @import("std");
const zbackoff = @import("zbackoff");
fn funcThatCanFail() !u64 {
_ = try std.time.Instant.now();
std.debug.print("funcThatFails()\n", .{});
return error.UnwantedResult1;
}
pub fn main() void {
var bo = zbackoff.Backoff{};
for (0..3) |_| {
const result = funcThatCanFail() catch {
std.time.sleep(bo.pause());
continue;
};
_ = result;
break;
}
}
```