diff --git a/control.lua b/control.lua index d7f7ebb..edeb593 100644 --- a/control.lua +++ b/control.lua @@ -29,21 +29,19 @@ function Aux.control.event_listener(event, action) local listener = { event=event, action=action } - function self.set_action(action) + function self:set_action(action) listener.action = action end - function self.start() + function self:start() Aux.util.set_add(event_listeners, listener) - if not Aux.util.any(event_listeners, function(l) return l.event == event end) then - AuxControlFrame:RegisterEvent(event) - end + AuxControlFrame:RegisterEvent(event) return self end - function self.stop() + function self:stop() listener.deleted = true - if not Aux.util.any(event_listeners, function(l) return l.event == event end) then + if not Aux.util.any(Aux.util.set_to_array(event_listeners), function(l) return l.event == event end) then AuxControlFrame:UnregisterEvent(event) end return self @@ -57,16 +55,16 @@ function Aux.control.update_listener(action) local listener = { action=action } - function self.set_action(action) + function self:set_action(action) listener.action = action end - function self.start() + function self:start() Aux.util.set_add(update_listeners, listener) return self end - function self.stop() + function self:stop() listener.deleted = true return self end @@ -79,36 +77,36 @@ end function Aux.control.on_next_update(callback) local listener = Aux.control.update_listener() - listener.set_action(function() + listener:set_action(function() listener:stop() return callback() end) - listener.start() + listener:start() end function Aux.control.on_next_event(event, callback) local listener = Aux.control.event_listener(event) - listener.set_action(function() + listener:set_action(function() listener:stop() return callback() end) - listener.start() + listener:start() end function Aux.control.as_soon_as(p, callback) local listener = Aux.control.update_listener() - listener.set_action(function() + listener:set_action(function() if p() then - listener.stop() + listener:stop() return callback() end end) - listener.start() + listener:start() end @@ -119,14 +117,14 @@ function Aux.control.controller() local state local listener = Aux.control.update_listener() - listener.set_action(function() + listener:set_action(function() if state and state.p() then local k = state.k state = nil return k() end end) - listener.start() + listener:start() function self.wait(p, k) state = { @@ -135,11 +133,11 @@ function Aux.control.controller() } end - function self.reset() + function self:reset() state = nil end - function self.cleanup() + function self:cleanup() listener.stop() end diff --git a/post_frame.lua b/post_frame.lua index 24dbf11..73a8299 100644 --- a/post_frame.lua +++ b/post_frame.lua @@ -778,7 +778,6 @@ function private.refresh_entries() private.status_bar:set_text('Scanning auctions...') Aux.scan.start{ - no_wait_owners = true, queries = { query }, on_page_loaded = function(page, total_pages) private.status_bar:update_status(100 * (page + 1) / total_pages, 0) -- TODO diff --git a/scan.lua b/scan.lua index 7929734..4d43bdf 100644 --- a/scan.lua +++ b/scan.lua @@ -71,32 +71,39 @@ function wait_for_results(k) end) end else - Aux.control.on_next_event('AUCTION_ITEM_LIST_UPDATE', function() + local last_update + local listener = Aux.control.event_listener('AUCTION_ITEM_LIST_UPDATE') + listener:set_action(function() + private.request_owner_data() + last_update = GetTime() + end) + listener:start() + Aux.control.as_soon_as(function() return last_update and GetTime() - last_update > 3 end, function() + listener:stop() ok = true end) end - return controller().wait(function() return ok end, k) + local t0 = GetTime() + return controller().wait(function() return ok or GetTime() - t0 > 30 end, k) end -function wait_for_owner_data(k) - if state.params.no_wait_owners then - return k() +function private.owner_data_complete() + local count, _ = GetNumAuctionItems(current_query().type) + for i=1,count do + local auction_info = Aux.info.auction(i, current_query().type) + if auction_info and not auction_info.owner then + return false + end + end + return true +end + +function private.request_owner_data() + local count, _ = GetNumAuctionItems(current_query().type) + for i=1,count do + Aux.info.auction(i, current_query().type) end - local t0 = time() - return controller().wait(function() - if time() - t0 > 30 then -- we won't wait longer than 30 seconds - return true - end - local count, _ = GetNumAuctionItems(current_query().type) - for i=1,count do - local auction_info = Aux.info.auction(i, current_query().type) - if auction_info and not auction_info.owner then - return false - end - end - return true - end, k) end function wait_for_callback(args) -- the arguments must not be nil! @@ -202,17 +209,15 @@ function submit_query(k) state.params.on_submit_query() end wait_for_results(function() - wait_for_owner_data(function() - local _, total_count = GetNumAuctionItems(current_query().type) - state.total_pages = math.ceil(total_count / PAGE_SIZE) - if state.total_pages >= state.page + 1 then - wait_for_callback{state.params.on_page_loaded or Aux.util.pass, state.page, state.total_pages, function() - return k() - end} - else + local _, total_count = GetNumAuctionItems(current_query().type) + state.total_pages = math.ceil(total_count / PAGE_SIZE) + if state.total_pages >= state.page + 1 then + wait_for_callback{state.params.on_page_loaded or Aux.util.pass, state.page, state.total_pages, function() return k() - end - end) + end} + else + return k() + end end) if current_query().type == 'bidder' then GetBidderAuctionItems(state.page)