Erlang (programming language)/Tutorials/Timeouts: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Eric Evers
(New page: =Timeouts= Timeouts are created by the [ receive - after - end ] structure. Timeouts are measured in miliseconds so 4000 = 4 seconds. We can create a simple timer with the following progr...)
 
imported>Chris Day
No edit summary
Line 1: Line 1:
{{subpages}}
=Timeouts=
=Timeouts=



Revision as of 12:27, 22 April 2008


Timeouts

Timeouts are created by the [ receive - after - end ] structure. Timeouts are measured in miliseconds so 4000 = 4 seconds. We can create a simple timer with the following program: myTimer.erl

% ============================================================ >%
-module( myTimer ).
-compile( export_all ).
                                                                %
% A simple timer that uses a timeout.
                                                                %
start( Timeout ) ->
    receive
    after Timeout ->
        io:format( "your ~w secs are up." , [Timeout/1000] )
    end.	
% ============================================================ >%
%
% Sample output:
% 
% 8> c(myTimer).
% ok.
%
% 9> myTimer:start(4000).
% your 4.00000 secs are up.ok