#331·actix

Add `SyncArbiter::start_once` that takes a `FnOnce` closure

Author: david-mcgillicuddy-moixaCreated Feb 10, 2020Updated Mar 10, 2021

Currently using SyncArbiter::start with only one thread we have to do some clones that we could otherwise avoid:

let config: Config = unimplemented!(); // implements Clone, not Copy
SyncArbiter::start(1, move || {
    let config = config.clone();
    MySyncActor(config)
}

It would be nice if this was special cased with a start_once method, or similar. With a FnOnce closure, instead of Fn, I believe you could move variable inside properly. It's even worse with types you can't clone and then you're throwing around Arcs etc.

One additional advantage of this is that we could potentially also signal failure, i.e. allow the inner FnOnce to return a Result.

If there's interest I'm happy to put this together - it should be mostly copy pasting the existing start method.