-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Library support for go-like deferred function #1523
Comments
Maybe there's some way to build something that looks like try finally. It's not safe to put a block into a resource, but we could do it unsafely if we can guarantee the resource doesn't escape. Something that looks vaguely like:
Could be implemented. |
So this works:
The only problem is that the try block is a fn@ not a fn& because of limitations on where you can write fn&. |
It seems to me that we should just define an inline resource syntax. Admittedly, the "finally" code then appears at the top---but that kind of makes sense to me. D has something similar: a way to say, "this code will run on all exits" |
I took another stab at it:
It's hideous, but it's all stack closures. |
If resources are going away, to be replaced with classes, how does that affect this issue? Currently it doesn't seem possible to have "anonymous" classes, since classes are inherently nominal. |
I'm hoping that classes with region fields can be used to build defer, but I don't know how. |
Closing this because the last activity was 10 months ago and I'm going to assume that was @brson was hoping for is true. Reopen if necessary. |
* Remove `Invariant` from stdlib example * Remove `Invariant` from Firecracker example * Format * Use `Self` and remove trivial `is_valid` methods * Remove leftover semicolon
I recently wrote the following to get some behavior like a 'finally' block:
What I really wanted to write was:
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.The text was updated successfully, but these errors were encountered: