performance improvements

This commit is contained in:
Manuel Simon Hirsig
2016-11-06 22:31:13 +01:00
parent 7acf677516
commit 23d79f65ad
3 changed files with 11 additions and 9 deletions
+2 -2
View File
@@ -127,7 +127,7 @@ do
do (on_success or nop)() end
locked = false
end)
thread(when, later(GetTime(), 5), send_signal)
thread(when, later(5), send_signal)
event_listener('CHAT_MSG_SYSTEM', function(kill)
if arg1 == ERR_AUCTION_BID_PLACED then
send_signal()
@@ -150,7 +150,7 @@ do
do (on_success or nop)() end
locked = false
end)
thread(when, later(GetTime(), 5), send_signal)
thread(when, later(5), send_signal)
event_listener('CHAT_MSG_SYSTEM', function(kill)
if arg1 == ERR_AUCTION_REMOVED then
send_signal()
+4 -4
View File
@@ -156,7 +156,7 @@ function scan_page(i)
end
function wait_for_results()
local timeout = later(state.last_query_time, 10)
local timeout = later(5, state.last_query_time)
local send_signal, signal_received = signal()
when(signal_received, function()
if timeout() then
@@ -181,7 +181,7 @@ function wait_for_results()
elseif state.params.type == 'owner' then
return wait_for_owner_results(send_signal)
elseif state.params.type == 'list' then
return wait_for_list_results(send_signal, signal_received)
return wait_for_list_results(send_signal, signal_received, timeout)
end
end
@@ -193,7 +193,7 @@ function wait_for_owner_results(send_signal)
end
end
function wait_for_list_results(send_signal, signal_received)
function wait_for_list_results(send_signal, signal_received, timeout)
local updated, last_update
event_listener('AUCTION_ITEM_LIST_UPDATE', function(kill)
kill(signal_received())
@@ -203,7 +203,7 @@ function wait_for_list_results(send_signal, signal_received)
local ignore_owner = state.params.ignore_owner or aux_ignore_owner
return thread(when, function()
-- short circuiting order important, owner_data_complete must be called iif an update has happened.
local ok = updated and (ignore_owner or owner_data_complete()) or last_update and GetTime() - last_update > 5
local ok = updated and (ignore_owner or owner_data_complete() or timeout())
updated = false
return ok
end, send_signal)
+5 -3
View File
@@ -209,10 +209,12 @@ function M.round(x)
return floor(x + .5)
end
function M.later(t0, t)
function M.later(t, t0)
t0 = t0 or GetTime()
return function() return GetTime() - t0 > t end
end
function M.signal() local params
return function(...) params = arg end, function() return params end
function M.signal()
local params
return vararg-function(arg) params = static-arg end, function() return params end
end