After using Actor::kill, is it still necessary to call JoinHandle.await? #174
-
When I exit a actor, I first call ActorCell::stop, then call JoinHandle.await. Suppose I didn't save JoinHandle, can I directly use ActorCell::kill? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You should await the joinhandle ideally, it'll interrupt the messaging task under the hood, however there is some non-instant cleanup which needs to execute for the actor to fully die. If you don't await the handle, and immediately exit, you may have a form of memory-leak because tokio will have some pending tasks living around. You generally don't need to wait on the handles if you're not immediately shutting down however, so in "general" you just do it on the root-process inside the |
Beta Was this translation helpful? Give feedback.
You should await the joinhandle ideally, it'll interrupt the messaging task under the hood, however there is some non-instant cleanup which needs to execute for the actor to fully die. If you don't await the handle, and immediately exit, you may have a form of memory-leak because tokio will have some pending tasks living around.
You generally don't need to wait on the handles if you're not immediately shutting down however, so in "general" you just do it on the root-process inside the
main
of your process to not exit the process too quickly.