[newbie] accept()-ing process under supervision (was:Erlangish way of Iterator pattern)

Mark Scandariato mscandar@REDACTED
Wed Jan 26 19:39:29 CET 2005


Vance Shipley wrote:
> On Wed, Jan 26, 2005 at 04:07:29PM +0100, Joe Armstrong (AL/EAB) wrote:
> }  
> }  [almost] - the code above is incorrect - and is merely to illustrate the idea -
> }  why is it incorrect? (ten brownie points for the first correct explanation of the error :-)
> 
> I'm not sure what you're looking for.  Mainly the fun to handle
> the exit reason is being called with Reason only but expects the
> full {'EXIT', Pid, Reason} message.  Other wise, with some syntax
> corrections, it seems to work:

My take on it was:

keep_alive(Fun) ->
     on_exit(spawn(Fun),
             fun
                 (normal) -> true;
                 (_) -> keep_alive(Fun)
             end).



<snip>
> 
> Although I'd say the main problem is that since it doesn't spawn_link
> it is possible for the process to exit before the link takes place.
> 
> 	-Vance
> 

If Pid exits before the link, then the linking process will receive {'EXIT', Pid, noproc}. 
(And will call Fun(noproc)).



More information about the erlang-questions mailing list