Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow defer in jd2 and jd3? #10

Closed
Ruulul opened this issue Mar 19, 2024 · 1 comment
Closed

allow defer in jd2 and jd3? #10

Ruulul opened this issue Mar 19, 2024 · 1 comment

Comments

@Ruulul
Copy link

Ruulul commented Mar 19, 2024

Using defer on pairs of setup and cleanup is a common zig idiom, but since the end() functions can error, its impossible right now.

Suggested refactor:

  • make an error union variable;
  • rewrite the try expressions to catch, save the error and return;
  • make begin() try the end error as the first thing;

so it would be something like

+ var end_error: anyerror!void = {};
...
pub fn begin(opt: BeginOpt) !void {
    + try end_error;
    ....
}
...
-pub fn end() !void {
+pub fn end() void {
-    try [expr];
+    [expr] catch |e| return end_error = e;
}

Gonna write down a PR, just thought it would be good to open an issue first.

@Jack-Ji
Copy link
Owner

Jack-Ji commented Mar 20, 2024

Hi @Ruulul, thanks for the PR. Believe it or not, j2d.end and j3d.end used to be void functions. I don't quite remember why I changed them, maybe some errors were too important to be ignored at the time. Anyway, both functions have been refactored many times after then, I think it's ok to simply make them void functions again.

@Jack-Ji Jack-Ji closed this as completed Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants