Skip to content

Add a @defer function #12302

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

Closed
dullbananas opened this issue Jul 30, 2022 · 1 comment
Closed

Add a @defer function #12302

dullbananas opened this issue Jul 30, 2022 · 1 comment

Comments

@dullbananas
Copy link

With this built-in function, it would be possible for functions to accept @defer or null as an argument to prevent forgetting to defer something.

For example, ArenaAllocator could be used like this:

let foo = ArenaAllocator.init(@defer, alloc);

Manually calling deinit:

let foo = ArenaAllocator.init(null, alloc);
foo.deinit()

The init function calls the provided defer function, defer_arg, like this (requires closure stntax):

if (defer_arg) |defer| {
    defer(fn() void {
        self.deinit()
    });
}
@InKryption
Copy link
Contributor

Duplicate of #782.

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

3 participants