Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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;
}
}
```