From 5fa8b8fab4e13bd3c53c22539d38df5df0afa4cf Mon Sep 17 00:00:00 2001
From: Sophist <github@sodalis.co.uk>
Date: Wed, 24 Feb 2016 01:40:24 +0000
Subject: [PATCH 1/2] Add Abort function to Async Wrapper

WinHTTP supports an Abort function to allow a request to be cancelled.

This PR provides a method for user to abort the call and ensures that requests are cancelled if the user deallocated the wrapper object before the request has completed.
---
 src/WebAsyncWrapper.cls | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/WebAsyncWrapper.cls b/src/WebAsyncWrapper.cls
index f10d4eeb..fd8ec4f4 100644
--- a/src/WebAsyncWrapper.cls
+++ b/src/WebAsyncWrapper.cls
@@ -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 "Class Terminate" & Reason, "WebAsyncWrapper.Cancel"
+        End If
+    End If
     Set Me.Client = Nothing
     Set Me.Request = Nothing
 End Sub
-

From f0c4d901f8619f9484a3265aa1c4af8fcfbe5fdf Mon Sep 17 00:00:00 2001
From: Sophist <github@sodalis.co.uk>
Date: Wed, 24 Feb 2016 02:03:16 +0000
Subject: [PATCH 2/2] Fix buggette

---
 src/WebAsyncWrapper.cls | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/WebAsyncWrapper.cls b/src/WebAsyncWrapper.cls
index fd8ec4f4..82f3f73f 100644
--- a/src/WebAsyncWrapper.cls
+++ b/src/WebAsyncWrapper.cls
@@ -268,7 +268,7 @@ Private Sub Class_Terminate()
         If WebHelpers.AsyncRequests.Exists(Me.Request.Id) Then
             Me.Http.Abort
             WebHelpers.AsyncRequests.Remove Me.Request.Id
-            WebHelpers.LogDebug "Class Terminate" & Reason, "WebAsyncWrapper.Cancel"
+            WebHelpers.LogDebug "Aborted - Class Terminated", "WebAsyncWrapper.Cancel"
         End If
     End If
     Set Me.Client = Nothing