aboutsummaryrefslogtreecommitdiff
path: root/mirai/crimson/propagate/wait.zig
diff options
context:
space:
mode:
Diffstat (limited to 'mirai/crimson/propagate/wait.zig')
-rw-r--r--mirai/crimson/propagate/wait.zig48
1 files changed, 48 insertions, 0 deletions
diff --git a/mirai/crimson/propagate/wait.zig b/mirai/crimson/propagate/wait.zig
new file mode 100644
index 0000000..6370e20
--- /dev/null
+++ b/mirai/crimson/propagate/wait.zig
@@ -0,0 +1,48 @@
+//! Wait for Exception Reply
+
+const types = @import("../types/types.zig");
+const constants = @import("../constants/constants.zig");
+const handlers = @import("../handlers/handlers.zig");
+
+const Exception = types.Exception;
+const Port = types.Port;
+const Action = constants.Action;
+
+pub const Reply = struct {
+ action: Action,
+ new_state: bool,
+ valid: bool,
+};
+
+pub fn wait_for_reply(exception: *Exception, port: *const Port) Action {
+ _ = port;
+
+ const reply = receive_reply();
+
+ if (!reply.valid) {
+ return handlers.default_action(exception.exception_type);
+ }
+
+ if (reply.new_state) {
+ apply_new_state(exception);
+ }
+
+ return reply.action;
+}
+
+fn receive_reply() Reply {
+ return Reply{
+ .action = .terminate,
+ .new_state = false,
+ .valid = true,
+ };
+}
+
+fn apply_new_state(exception: *Exception) void {
+ _ = exception;
+}
+
+pub fn wait_with_timeout(exception: *Exception, port: *const Port, timeout_ms: u64) Action {
+ _ = timeout_ms;
+ return wait_for_reply(exception, port);
+}