-1

I have implemented an actix actor including the Supervised trait. I then tried to start the actor in a supervised way using

let _: Addr<Unsync, _> = Supervisor::start(|_| MyActor::default());

Unfortunately when that actor stops it is not automatically restarted for some reason.


Dependency Versions

actix = "0.5"
TBieniek
  • 4,858
  • 2
  • 24
  • 29

1 Answers1

0

Nikolay Kim, the author of actix, helped me analyze the issue. It turns out that assigning the Supervisor::start() result to a variable called _ will automatically throw away the result and so the supervisor will not actually start correctly.

The solution to this issue is renaming the _ variable to _addr:

let _addr: Addr<Unsync, _> = Supervisor::start(|_| MyActor::default());

After the rename the Supervisor correctly restarts the MyActor actor after it has stopped.

TBieniek
  • 4,858
  • 2
  • 24
  • 29
  • don't make any sense. – Stargateur May 25 '18 at 11:11
  • 3
    This is part of a more generic aspect of binding a value to `_`: unlike in other languages, `_` is a special token, not a variable name. It is used explicitly not to bind the value to anything, so the given `Addr` is immediately dropped. Whether this would influence how actix works, that would depend on the crate's implementation details. – E_net4 May 25 '18 at 12:49