<div dir="ltr">Hi,<br><div class="gmail_extra"><div><div dir="ltr"><br></div><div dir="ltr">What you want is something like Interrupts. I don't think Erlang processes have interrupts. So there is no easy solution. But you can do it using message passing which will require multiple processes.</div>
<div dir="ltr"><br></div><div dir="ltr">To elaborate, you create another process to check records while this process waits for more messages. When you receive a stop message, you kill the process who is checking for records. On the other hand, if the process is done executing (i.e. done checking records) it simply sends a success message to the parent process.</div>
<div dir="ltr"><br></div><div dir="ltr">You can read more here <a href="http://stackoverflow.com/questions/10219058/interrupting-a-process-in-erlang">http://stackoverflow.com/questions/10219058/interrupting-a-process-in-erlang</a><br>
<br><font style="color:rgb(102,51,51);font-family:tahoma,sans-serif">Aman Mangal</font><div><font style="color:rgb(102,51,51);font-family:tahoma,sans-serif">4th year Undergraduate Student<br>Department of Computer Science & Engineering<br>
IIT Bombay<br></font><a href="http://www.cse.iitb.ac.in/~amanmangal" target="_blank">www.cse.iitb.ac.in/~amanmangal</a>
</div></div></div>
<br><br><div class="gmail_quote">On Fri, Nov 8, 2013 at 3:13 PM, Janos Hary <span dir="ltr"><<a href="mailto:janos.n.hary@gmail.com" target="_blank">janos.n.hary@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Sorry, I cannot see how could it work in Erlang.<br>
<br>
I have a handle_info processing a large number of records:<br>
handle_info(check, State) -><br>
check_records(State).<br>
<br>
check_records(State) -><br>
do some work...<br>
case State#stop_flag of<br>
true -><br>
{stop, normal, State};<br>
_ -><br>
check_records(State)<br>
end.<br>
<br>
The State in check_records cannot changed from another cast. I'm not even<br>
sure that the cast will execute before check_records finishes.<br>
<span class=""><font color="#888888"><br>
Janos<br>
</font></span><div class=""><div class="h5"><br>
<br>
-----Original Message-----<br>
From: <a href="mailto:erlang-questions-bounces@erlang.org">erlang-questions-bounces@erlang.org</a><br>
[mailto:<a href="mailto:erlang-questions-bounces@erlang.org">erlang-questions-bounces@erlang.org</a>] On Behalf Of Bengt Kleberg<br>
Sent: Friday, November 08, 2013 9:28 AM<br>
To: undisclosed-recipients:<br>
Cc: <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
Subject: Re: [erlang-questions] Stopping gen_server during processing<br>
<br>
These are my opinions, not hard facts.<br>
<br>
Add a member to the gen_server state record that says that you are going to<br>
stop when possible. Use a cast to set it to true when you want to stop. If<br>
it is true and you can stop the gen_server, stop it.<br>
<br>
<br>
bengt<br>
<br>
On Fri, 2013-11-08 at 08:55 +0100, Janos Hary wrote:<br>
> All,<br>
><br>
><br>
><br>
> I have a gen_server process which periodically processes new records<br>
> from a database. I use timer:send_after to schedule gathering and<br>
> processing new records. I can gracefully stop the gen_server when it<br>
> is waiting, but I need a way to stop it during processing. Of cause I<br>
> only want to stop it at certain points of the processing, for example<br>
> before starting to process the next record. I need to group the<br>
> records, so I cannot ask them one by one from the db.<br>
><br>
><br>
><br>
> What is the preferred way of doing this?<br>
><br>
><br>
><br>
> Thanks for your answers in advance.<br>
><br>
> Janos<br>
><br>
><br>
> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div></div>