[erlang-questions] Intrusive function intercept

Kostis Sagonas kostis@REDACTED
Thu Oct 10 10:15:35 CEST 2013

On 10/10/2013 10:02 AM, Tyron Zerafa wrote:
> Hi,
>      I would like to monitor a process and suspend the execution of
> certain functions to perform some other computation before. For instance
> consider a process A which executing the following simple function.
> test() ->
>      x(),
>      y(),
>      z().
> I would like to initiate a process, B, that monitors the execution of A.
> I want B to:
>    1) stop A before function y is executed
>    2) execute some logic
>    3) resumes the execution of A (by executing Y and Z)

How about changing that code to receive an appropriate message from B at 
the point(s) you want it to "execute that logic"?  Something like:

   test() ->
       %% B ! {done,x},             % optionally inform B that x is done
           {cont_msg, Fun} -> Fun() % execute the logic

Wouldn't that work?


More information about the erlang-questions mailing list