Is there a better way to write a timer in erlang otp 22

46 Views Asked by At

How do I write a timer in Erlang and how does it work?

For example, I'm trying to understand this code :

Function ({deliver_sm, Number, Time}) when Time == "Deliverd" -> 

      timer:sleep(600000),

      #what happens when number and time comes here from another node. It's like a parent and child. I have received a submit request from one node and I have to delay the node where it will send a response which is this deliver sm. 

I have tried using this timer sleep but the function is working fine without being put to sleep. Is there anyway to know that this sleep timer is working. For example can I possibly print the time when this timer gets triggered. Or Am I going in a wrong direction? Any suggestion is welcome and thank you

1

There are 1 best solutions below

0
7stud On

can I possibly print the time when this timer gets triggered.

do_stuff({deliver_sm, Number, Time}) when Time == "Deliverd" -> 

      io:format("Time just before timer was triggered: ~w~n", [erlang:system_time()]), 
      timer:sleep(600000),
      io:format("Time after sleeping: ~w~n", [erlang:system_time()]).