gen-server

How to perform actions periodically with Erlang's gen_server?

為{幸葍}努か 提交于 2019-11-29 21:21:40
I want to start a gen_server that additionally, will perform one action every minute. What is the best way to schedule that? You have two easy alternatives, use timer:send_interval/2 or erlang:send_after/3 . send_interval is easier to setup, while send_after (when used in the Erlang module) is more reliable since it is a built-in function, see the Efficiency Guide . Using send_after also ensures that the gen_server process is not overloaded. If you were using the send_interval function you would get a message regardless if the process can keep up or not. With send_after being called just

what kind of types can be sent on an erlang message?

只谈情不闲聊 提交于 2019-11-29 03:17:32
问题 Mainly I want to know if I can send a function in a message in a distributed Erlang setup. On Machine 1: F1 = Fun()-> hey end, gen_server:call(on_other_machine,F1) On Machine 2: handler_call(Function,From,State) -> {reply,Function(),State) Does it make sense? 回答1: Here's an interesting article about "passing fun's to other Erlang nodes". To resume it briefly: [...] As you might know, Erlang distribution works by sending the binary encoding of terms; and so sending a fun is also essentially

How to perform actions periodically with Erlang's gen_server?

折月煮酒 提交于 2019-11-28 18:49:12
问题 I want to start a gen_server that additionally, will perform one action every minute. What is the best way to schedule that? 回答1: You have two easy alternatives, use timer:send_interval/2 or erlang:send_after/3 . send_interval is easier to setup, while send_after (when used in the Erlang module) is more reliable since it is a built-in function, see the Efficiency Guide. Using send_after also ensures that the gen_server process is not overloaded. If you were using the send_interval function