Skip to content

Commit 0d07111

Browse files
authored
Defer creation of tradequery onframefunc (#2180)
1 parent 965fc6f commit 0d07111

1 file changed

Lines changed: 26 additions & 25 deletions

File tree

src/Classes/TradeQuery.lua

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,6 @@ local TradeQueryClass = newClass("TradeQuery", function(self, itemsTab)
5555
self.lastQueries = {}
5656

5757
self.tradeQueryRequests = new("TradeQueryRequests")
58-
local function onRateLimit(backoff)
59-
self.backoffFinish = get_time() + backoff
60-
self.countDown = coroutine.create(function()
61-
while self.backoffFinish do
62-
local now = get_time()
63-
if self.backoffFinish < (now + 0.5) then
64-
self.backoffFinish = nil
65-
self:SetNotice(self.controls.pbNotice, "")
66-
return
67-
end
68-
local msg = s_format("Rate limited. Retrying after %s seconds...", self.backoffFinish - now)
69-
self:SetNotice(self.controls.pbNotice, colorCodes.WARNING..msg)
70-
coroutine.yield()
71-
end
72-
end)
73-
end
74-
main.onFrameFuncs["TradeQueryRequests"] = function()
75-
self.tradeQueryRequests:ProcessQueue(onRateLimit)
76-
if self.countDown then
77-
coroutine.resume(self.countDown)
78-
if coroutine.status(self.countDown) == "dead" then
79-
self.countDown = nil
80-
end
81-
end
82-
end
8358
if not main.api then
8459
main.api = new("PoEAPI", main.lastToken, main.lastRefreshToken, main.tokenExpiry)
8560
end
@@ -609,6 +584,32 @@ Highest Weight - Displays the order retrieved from trade]]
609584
self.controls.scrollBar:SetContentDimension(self.pane_height-100, self.effective_rows_height)
610585
self.controls.sectionAnchor.y = -self.controls.scrollBar.offset
611586
end
587+
588+
local function onRateLimit(backoff)
589+
self.backoffFinish = get_time() + backoff
590+
self.countDown = coroutine.create(function()
591+
while self.backoffFinish do
592+
local now = get_time()
593+
if self.backoffFinish < (now + 0.5) then
594+
self.backoffFinish = nil
595+
self:SetNotice(self.controls.pbNotice, "")
596+
return
597+
end
598+
local msg = s_format("Rate limited. Retrying after %s seconds...", self.backoffFinish - now)
599+
self:SetNotice(self.controls.pbNotice, colorCodes.WARNING..msg)
600+
coroutine.yield()
601+
end
602+
end)
603+
end
604+
main.onFrameFuncs["TradeQueryRequests"] = function()
605+
self.tradeQueryRequests:ProcessQueue(onRateLimit)
606+
if self.countDown then
607+
coroutine.resume(self.countDown)
608+
if coroutine.status(self.countDown) == "dead" then
609+
self.countDown = nil
610+
end
611+
end
612+
end
612613
main:OpenPopup(pane_width, self.pane_height, "Trader", self.controls, nil, nil, "close", (scrollBarShown and scrollBarFunc or nil))
613614
end
614615

0 commit comments

Comments
 (0)