Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to cancel a message while it's being sent?

Tags:

erlang

Process A sends a request to B after 1 minute with send_after (let's call it request). But B has 1 minute to cancel it.

Can B send cancel to A and prevent that message being sent within this timespan?

like image 610
João Vilaça Avatar asked Mar 12 '23 04:03

João Vilaça


1 Answers

Yes you can.

When you are using erlang:send_after it returns a TimerRef. If you want to cancel the request you just need to call erlang:cancel_timer(TimerRef) or erlang:cancel_timer(TimerRef, Options).

In your case, if you want process B to cancel the message you will have to send TimerRef from A to B and then call erlang:cancel_timer(TimerRef) in process B in order to cancel this specific send request.

Please take a look at erlang documentation erlang:cancel_timer/2 for more information.

like image 135
A. Sarid Avatar answered Mar 21 '23 00:03

A. Sarid