Skip to content

Commit 810b823

Browse files
committed
Simplify timeout timer implementation
1 parent 23f3fdf commit 810b823

File tree

2 files changed

+9
-33
lines changed

2 files changed

+9
-33
lines changed

src/RestHelpers.bas

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ Attribute VB_Name = "RestHelpers"
3939

4040
#End If
4141

42-
Private Timers As Object
43-
4442
Public Enum StatusCodes
4543
Ok = 200
4644
Created = 201
@@ -230,13 +228,7 @@ End Function
230228
' @param {Long} TimeoutMS
231229
' --------------------------------------------- '
232230
Public Sub StartTimeoutTimer(Request As RestRequest, TimeoutMS As Long)
233-
If Timers Is Nothing Then: Set Timers = CreateObject("Scripting.Dictionary")
234-
235-
Dim Id As Long
236-
Id = SetTimer(Application.HWnd, ObjPtr(Request), TimeoutMS, AddressOf RestHelpers.TimeoutTimerExpired)
237-
238-
Timers.Add Id, Request
239-
Request.TimerId = Id
231+
SetTimer Application.HWnd, ObjPtr(Request), TimeoutMS, AddressOf RestHelpers.TimeoutTimerExpired
240232
End Sub
241233

242234
''
@@ -245,12 +237,7 @@ End Sub
245237
' @param {RestRequest} Request
246238
' --------------------------------------------- '
247239
Public Sub StopTimeoutTimer(Request As RestRequest)
248-
If Timers.Exists(Request.TimerId) Then
249-
KillTimer Application.HWnd, Request.TimerId
250-
251-
Timers.Remove Request.TimerId
252-
Request.TimerId = -1
253-
End If
240+
KillTimer Application.HWnd, ObjPtr(Request)
254241
End Sub
255242

256243
''
@@ -260,26 +247,14 @@ End Sub
260247
' --------------------------------------------- '
261248
#If VBA7 And Win64 Then
262249
Public Sub TimeoutTimerExpired(ByVal HWnd As Long, ByVal Msg As Long, _
263-
ByVal Id As Long, ByVal dwTimer As Long)
250+
ByVal Request As RestRequest, ByVal dwTimer As Long)
264251
#Else
265252
Sub TimeoutTimerExpired(ByVal HWnd As Long, ByVal uMsg As Long, _
266-
ByVal Id As Long, ByVal dwTimer As Long)
253+
ByVal Request As RestRequest, ByVal dwTimer As Long)
267254
#End If
268255

269-
If Timers.Exists(Id) Then
270-
Dim Request As RestRequest
271-
Set Request = Timers.Item(Id)
272-
273-
' If request is found, stop timer and call TimedOut()
274-
If Not Request Is Nothing Then
275-
StopTimeoutTimer Request
276-
Request.TimedOut
277-
Else
278-
KillTimer Application.HWnd, Id
279-
End If
280-
Else
281-
KillTimer Application.HWnd, Id
282-
End If
256+
StopTimeoutTimer Request
257+
Request.TimedOut
283258
End Sub
284259

285260
' ======================================================================================== '

src/RestRequest.cls

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ Public BaseUrl As String
6161
Public RequireHTTPS As Boolean
6262
Public CallbackArgs As Variant
6363
Public IncludeCacheBreaker As Boolean
64-
Public TimerId As Long
6564

6665
Public Property Get Headers() As Object
6766
If pHeaders Is Nothing Then: Set pHeaders = CreateObject("Scripting.Dictionary")
@@ -118,7 +117,9 @@ Public Property Get FormattedResource() As String
118117
' Add querystring
119118
If (Me.Method = httpGET And Not Me.Parameters Is Nothing) Or Not Me.QuerystringParams Is Nothing Then
120119
If (Me.Parameters.count > 0 And Me.Method = httpGET) Or Me.QuerystringParams.count > 0 Then
121-
FormattedResource = FormattedResource & "?"
120+
If InStr(FormattedResource, "?") <= 0 Then
121+
FormattedResource = FormattedResource & "?"
122+
End If
122123

123124
' Only load parameters to querystring if GET request (otherwise they are added to the body)
124125
If Me.Method = httpGET Then

0 commit comments

Comments
 (0)