可以用接收超时实现一个简单的定时器,函数stimer:start(Time,Fun)会在Time毫秒之后执行Fun(一个不带参数的函数),它返回一个句柄(是一个PID),可以在需要时用来关闭定时器。
-module(stimer).
-export([start/2,cancel/1]).
start(Time,Fun)->spawn(fun()->timer(Time,Fun) end).
cancel(Pid)->Pid!cancel.
timer(Time,Fun)->
receive
cancel->
void
after Time->
Fun()
end.
Erlang---定时器
猜你喜欢
转载自blog.csdn.net/m0_38127487/article/details/113753578
今日推荐
周排行