Use a selective receive, and ignore stale answers. I think this fixes #3

This commit is contained in:
Maas-Maarten Zeeman
2013-11-28 19:41:40 +01:00
parent 29ffe329c4
commit 9df3a49445
2 changed files with 16 additions and 3 deletions

View File

@@ -287,9 +287,18 @@ close({connection, _Ref, Connection}, Timeout) ->
%% Internal functions
receive_answer(Ref, Timeout) ->
Start = os:timestamp(),
receive
{Ref, Resp} -> Resp;
Other -> throw(Other)
{esqlite3, Ref, Resp} ->
Resp;
{esqlite3, _, _}=StaleAnswer ->
error_logger:warning_msg("Esqlite3: Ignoring stale answer ~p~n", [StaleAnswer]),
PassedMics = timer:now_diff(os:timestamp(), Start) div 1000,
NewTimeout = case Timeout - PassedMics of
Passed when Passed < 0 -> 0;
TO -> TO
end,
receive_answer(Ref, NewTimeout)
after Timeout ->
throw({error, timeout, Ref})
end.