Skip to content

Add a @defer function #12302

Closed
Closed
@dullbananas

Description

@dullbananas

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()
    });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions