puniverse / quasar

Fibers, Channels and Actors for the JVM
http://docs.paralleluniverse.co/quasar/
Other
4.55k stars 575 forks source link

BehaviourActor. Method init should be executed before spawn returns. #188

Open hsestupin opened 8 years ago

hsestupin commented 8 years ago

According to erlang spec starting behaviours guarantees that returned process pid would have valid state and would be ready to handle messages. So I think it would be correct to have suspendable analogue of spawn method in BehaviourActor which will initialise BehaviourActor inside, wouldn't it?

pron commented 8 years ago

How does init being called or not affect anything that can be observed about the actor from the outside? When the spawn method returns, the ActorRef is valid and ready to receive messages (although it may crash before handling even the first one, but Erlang doesn't guarantee anything more). What is it that Erlang guarantees and Quasar doesn't?

hsestupin commented 8 years ago

When the spawn method returns, the ActorRef is valid and ready to receive messages

Right, but we might want message handling strategy to be depend on init block, or why do we need init block otherwise? At the official documentation http://erlang.org/doc/design_principles/gen_server_concepts.html you could find an item 2.3 Starting a Gen_Server which states that:

gen_server:start_link is synchronous. It does not return until the gen_server has been initialized and is ready to receive requests

And if you look at source https://github.com/erlang/otp/blob/maint/lib/stdlib/src/gen_server.erl the same is true for gen_server:start

pron commented 8 years ago

The init block can still determine the message handling strategy. It is called before any messages are handled. But I think that there is a good case for waiting: error handling. In any event, we'll need to think about it some more.

hsestupin commented 8 years ago

So I rethink it once more. You are right, messages will not be handled untill init finishes. Yeah, sometimes we might want to get error from init block eagerly. But it seems it's super-minor task :)