Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Abort function to Async Wrapper #196

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/WebAsyncWrapper.cls
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,31 @@ Private Sub Http_OnResponseFinished()
web_RunCallback web_Response
End Sub

' Abort asynchronous request
Public Sub Abort(Optional Reason As String = "")
If Reason <> "" Then Reason = ": " & Reason
If Not WebHelpers.AsyncRequests Is Nothing And Not Me.Request Is Nothing Then
If WebHelpers.AsyncRequests.Exists(Me.Request.Id) Then
Me.Http.Abort
WebHelpers.AsyncRequests.Remove Me.Request.Id
WebHelpers.LogDebug "Aborted" & Reason, "WebAsyncWrapper.Abort"
Else
WebHelpers.LogDebug "Not running" & Reason, "WebAsyncWrapper.Abort"
End If
Else
WebHelpers.LogDebug "Not running" & Reason, "WebAsyncWrapper.Abort"
End If
End Sub

Private Sub Class_Terminate()
' Remove requests before terminating class instance
If Not WebHelpers.AsyncRequests Is Nothing And Not Me.Request Is Nothing Then
If WebHelpers.AsyncRequests.Exists(Me.Request.Id) Then
Me.Http.Abort
WebHelpers.AsyncRequests.Remove Me.Request.Id
WebHelpers.LogDebug "Aborted - Class Terminated", "WebAsyncWrapper.Cancel"
End If
End If
Set Me.Client = Nothing
Set Me.Request = Nothing
End Sub