mozilla/rust — Issue #1523: Library support for go-like deferred function
Author: brson
Created: 2012-01-14 22:38:12+00:00
State: open
Labels: feature, lib

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

```
resource finally(ch: comm::chan) {
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.