Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to atomatically delete specs of terminated children in a dynamic supervisor
    primarykey
    data
    text
    <p><em>No knowledge of USB needed for this question, just described it as it is to make the example more conrete.</em></p> <p>I'm trying to implement a dynamic supervisor for specific devices on a USB bus. These devices have addresses and appear and disappear during the lifetime of the system. </p> <p>For each device I need a dynamic child for my supervisor.</p> <p>These children are transient, so once they crash or terminate we don't restart them (because probably they are gone then).</p> <p>I have a process that scans the USB port at certain times and produces a list of all addresses of the USB devices I want to handle.</p> <p>I plan to call <code>supervisor:which_children/1</code> before each scan to find out which devices are present but have no child process running.</p> <p>In order to find out which addresses have children running I plan to create Id atoms for the childspec that contain the addresses (there are only a few addresses possible), e.g. <code>adr_12</code> if the child handles address <code>12</code>.</p> <p>When I try to start/restart missing children I have the somewhat ugly situation that the child specs are not automatically deleted when the transient child terminates or crashes (at least I think that it is so). So I would need code like this:</p> <pre><code>case supervisor:start_child(my_sup, Spec) of {error, already_present} -&gt; supervisor:restart_child(my_sup, Spec); Any -&gt; Any end </code></pre> <p>Then there is the problem that I don't know if <code>supervisor:which_children/1</code> also returns already terminated children.</p> <p>So it would be best if children would be deleted after they transiently terminate.</p> <p>Somehow all this feels inelegant to me so I'm asking myself (and you):</p> <p>How can I resolve this most elegantly?</p> <p>Is it better not to use a supervisor at all in this situation?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload