Elixir/Ports and external process wiring: Difference between revisions
light edits |
|||
| Line 85: | Line 85: | ||
This is where Erlang/OTP really starts to shine: our rsync library wraps the Port calls under a gen_server<ref>https://www.erlang.org/doc/apps/stdlib/gen_server.html</ref> module and this gives us some special properties for free: a dedicated thread which coordinates with rsync independently from anything else, receiving and sending asynchronous messages. It has an internal state including the latest percent done and this can be probed by calling code, or it can be set up to push updates to a listener. | This is where Erlang/OTP really starts to shine: our rsync library wraps the Port calls under a gen_server<ref>https://www.erlang.org/doc/apps/stdlib/gen_server.html</ref> module and this gives us some special properties for free: a dedicated thread which coordinates with rsync independently from anything else, receiving and sending asynchronous messages. It has an internal state including the latest percent done and this can be probed by calling code, or it can be set up to push updates to a listener. | ||
A gen_server should | A gen_server should be able to run under a [https://adoptingerlang.org/docs/development/supervision_trees/ OTP supervision tree] as well but our module has a major flaw: although it can correctly detect and report when rsync crashes or completes, when our gen_server is stopped by its supervisor it cannot stop its external child process in turn. | ||
== Problem: runaway processes == | == Problem: runaway processes == | ||