, , - trapExit, case Exit exit, system. trapExit true:
def act() {
trapExit = true
link(workerA)
link(workerB)
...
}
, - "", , :
// Foreman
def act() {
....
loop { react {
case Exit (worker: Actor, reason: AnyRef) => {
// decrement counter, or list of workers, and exit if empty
}
...
}}
}
reason. , , , :
exit(WorkComplete)
exit(Emergency)
.. .. , Exit, . , - :
def act() {
....
loop { react {
case Exit (worker: Actor, reason: WorkComplete) => {
}
case Exit (worker: Actor, reason: TasksExhausted) => {
}
case Exit (worker: Actor, reason: Exception) => {
}
...
}}
}
It is not clear from your initial question whether you want the workers to continue to work even when they are finished, until the team leader tells them that they should leave when this time. If this is the case, sending employees messages telling them to "exit when finished" works, and you can say that they finished using the trapExit mechanism.
Hope this caused an interesting solution!
source
share