Deferred would take a dispatcher::Thunk and invoke it when it's dropped. This can make bridging threads and actors a little nicer. I've had to implement this pattern a few times .
e.g.
#[allow(unused_variables)]
let deferred = Deferred::new(move || {
// do some cleanup stuff
});
// other code
which would be an alternative to doing:
struct Hook { ... fields ... };
impl Drop for Hook {
fn drop(&mut self) {
// do some cleanup stuff
}
}
#[allow(unused_variables)]
let deferred_ = Hook { .. };
// do stuff
note that in both cases, the "cleanup" code is invoked whether the thread panics or not.
(name tbd)
Deferred would take a
dispatcher::Thunk
and invoke it when it's dropped. This can make bridging threads and actors a little nicer. I've had to implement this pattern a few times .e.g.
which would be an alternative to doing:
note that in both cases, the "cleanup" code is invoked whether the thread panics or not.