THRIFT-3820 Erlang: Detect OTP >= 18 to use new time correction
erlang:now/0 is deprecated BIF.
See the "Time and Time Correction in Erlang" chapter of the ERTS User's Guide for more information.
This closes #1000
diff --git a/lib/erl/src/thrift_reconnecting_client.erl b/lib/erl/src/thrift_reconnecting_client.erl
index 6731eab..468c38b 100644
--- a/lib/erl/src/thrift_reconnecting_client.erl
+++ b/lib/erl/src/thrift_reconnecting_client.erl
@@ -115,9 +115,9 @@
_From,
State=#state{ client = Client } ) ->
- Start = now(),
+ Timer = timer_fun(),
Result = ( catch thrift_client:call( Client, Op, Args) ),
- Time = timer:now_diff( now(), Start ),
+ Time = Timer(),
case Result of
{ C, { ok, Reply } } ->
@@ -217,6 +217,21 @@
false -> Backoff
end.
+-ifdef(time_correction).
+timer_fun() ->
+ T1 = erlang:monotonic_time(),
+ fun() ->
+ T2 = erlang:monotonic_time(),
+ erlang:convert_time_unit(T2 - T1, native, micro_seconds)
+ end.
+-else.
+timer_fun() ->
+ T1 = erlang:now(),
+ fun() ->
+ T2 = erlang:now(),
+ timer:now_diff(T2, T1)
+ end.
+-endif.
incr_stats( Op, Result, Time,
State = #state{ op_cnt_dict = OpCntDict,