by sly010 · 9y ago · 0 comments
func actor_foo(things) error {
set_up_stuff()
defer clean_up_stuff()
for {
select {
case msg := <-messages:
switch msg.(type) {
case *Bla:
}
case <- other_messages:
case <- errors:
case <- signals:
return nil
}
}
}
I recognize there is more to the actor model than just message loops, but I found that an explicit for-select-switch results in better overall readability.If parent need a "done" channel, it passes it in and "actor" closes it on its way out.
Cleanup usually "signals" children and waits for them to be "done".
Sometimes "done" is just signalled by the goroutine returning and it is wrapped in parent somehow.
But every time I try to formalize it into some "framework" my abstraction fails.