Polling design pattern.
Although it is preferable to see things happening in Erlang in terms of real-time events or messages, sometimes it is unavoidable to poll (periodically check a resource.)
This module provides a compromise by making polling look like plain Erlang messages, even though it is not technically in real-time.
loop/4 | Drives the polling. |
start/2 | Starts a polling service. |
test/0 | Test function. |
loop(Function::'fun'(), Interval::integer(), Parent::pid(), Value::term()) -> never_returns()
Drives the polling. This function is spawned by start/2
and should not be used by external callers.
start(Function::'fun'(), Interval::integer()) -> {ok, pid()} | {error, Reason}
Starts a polling service. Function (a fun/0) will be called
immediately, and every Interval milliseconds thereafter.
Each time the return value of it has changed from the previous value,
a message {ce_poll, pid(), NewValue}
will be sent to the process that called start/2
.
test() -> never_returns()
Test function. Monitors the current directory and displays file additions and removals no more than a second later than they happen.
Generated by EDoc, Dec 25 2007, 02:37:42.