-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexample_signal.zig
50 lines (33 loc) · 961 Bytes
/
example_signal.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const std = @import("std");
const pike = @import("pike.zig");
const os = std.os;
const log = std.log;
pub fn main() !void {
try pike.init();
defer pike.deinit();
const notifier = try pike.Notifier.init();
defer notifier.deinit();
var stopped = false;
var frame = async run(¬ifier, &stopped);
while (!stopped) {
try notifier.poll(10_000);
}
try nosuspend await frame;
}
fn run(notifier: *const pike.Notifier, stopped: *bool) !void {
var event = try pike.Event.init();
defer event.deinit();
try event.registerTo(notifier);
var signal = try pike.Signal.init(.{ .interrupt = true });
defer signal.deinit();
defer {
stopped.* = true;
event.post() catch unreachable;
}
log.info("Press Ctrl+C.", .{});
try signal.wait();
log.info("Do it again!", .{});
try signal.wait();
log.info("I promise; one more time.", .{});
try signal.wait();
}