Skip to content

Library support for go-like deferred function #1523

Closed
@brson

Description

@brson

I recently wrote the following to get some behavior like a 'finally' block:

        resource finally(ch: comm::chan<monitor_msg>) {                                                                                            
            comm::send(ch, done);                                                                                                                  
        }                                                                                                                                          

        let _finally = finally(ch);

What I really wanted to write was:

defer {||
    comm::send(ch, done);
}

Or something structured like try/finally.

I tried to devise some way to write a defer library function but there doesn't seem to be any safe way to do it since blocks can't be put into resources.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions