Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flowerinthenight/zbackoff
Jittered backoff implementation in Zig.
https://github.com/flowerinthenight/zbackoff
backoff jitter retry zig ziglang
Last synced: 9 days 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 (7 months ago)
- Default Branch: main
- Last Pushed: 2024-10-05T06:02:45.000Z (4 months ago)
- Last Synced: 2024-12-30T13:38:02.037Z (about 1 month ago)
- Topics: backoff, jitter, retry, zig, ziglang
- Language: Zig
- Homepage: https://github.com/flowerinthenight/zbackoff
- Size: 33.2 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Main](https://github.com/flowerinthenight/zbackoff/actions/workflows/main.yml/badge.svg)](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;
}
}
```