diff options
author | Peter Andersson <[email protected]> | 2011-09-16 23:37:29 +0200 |
---|---|---|
committer | Peter Andersson <[email protected]> | 2011-09-23 12:24:55 +0200 |
commit | b21b1f63bce0ad705671e0f7622d017be464ed67 (patch) | |
tree | 4b8ce319d2a16f846f959370a485fa103690c9f5 /lib/test_server/src/test_server.erl | |
parent | 36f1e1898a2ea08d591739cc2e9ff8e7fbb0ea6b (diff) | |
download | otp-b21b1f63bce0ad705671e0f7622d017be464ed67.tar.gz otp-b21b1f63bce0ad705671e0f7622d017be464ed67.tar.bz2 otp-b21b1f63bce0ad705671e0f7622d017be464ed67.zip |
Implement support for MFA and Fun as timetrap value
OTP-9501
Diffstat (limited to 'lib/test_server/src/test_server.erl')
-rw-r--r-- | lib/test_server/src/test_server.erl | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/test_server/src/test_server.erl b/lib/test_server/src/test_server.erl index 337bc1d6d7..039ea720a8 100644 --- a/lib/test_server/src/test_server.erl +++ b/lib/test_server/src/test_server.erl @@ -1905,8 +1905,28 @@ time_ms({Other,_N}) -> exit({invalid_time_spec,Other}); time_ms(Ms) when is_integer(Ms) -> Ms; time_ms(infinity) -> infinity; +time_ms(Fun) when is_function(Fun) -> + try Fun() of + Val -> time_ms1(Val) + catch + _:Error -> + exit({timetrap_error,Error}) + end; +time_ms({M,F,A}) when is_atom(M), is_atom(F), is_list(A) -> + try apply(M, F, A) of + Val -> time_ms1(Val) + catch + _:Error -> + exit({timetrap_error,Error}) + end; time_ms(Other) -> exit({invalid_time_spec,Other}). +time_ms1(MFA = {M,F,A}) when is_atom(M), is_atom(F), is_list(A) -> + exit({invalid_time_spec,MFA}); +time_ms1(Fun) when is_function(Fun) -> + exit({invalid_time_spec,Fun}); +time_ms1(Other) -> + time_ms(Other). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% timetrap_cancel(Handle) -> ok |