From cfb5488a8239fbabaab9c88c69f4068b8e87eb62 Mon Sep 17 00:00:00 2001 From: Colin Sullivan Date: Thu, 26 May 2016 09:39:41 -0600 Subject: [PATCH 1/2] Minor optimization - avoid unnecessarily throwing an exception. --- NATS/Conn.cs | 7 +------ NATS/Subscription.cs | 14 ++++++++++++-- NATSUnitTests/NATSUnitTests.csproj | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/NATS/Conn.cs b/NATS/Conn.cs index 7ce23502b..3f38c8d67 100755 --- a/NATS/Conn.cs +++ b/NATS/Conn.cs @@ -1903,12 +1903,7 @@ internal virtual Msg request(string subject, byte[] data, int timeout) publish(subject, inbox, data); Flush(); m = s.NextMessage(timeout); - try - { - // the auto unsubscribe should handle this. - s.Unsubscribe(); - } - catch (Exception) { /* NOOP */ } + s.unsubscribe(false); return m; } diff --git a/NATS/Subscription.cs b/NATS/Subscription.cs index d46e83c20..ce2bc62b8 100755 --- a/NATS/Subscription.cs +++ b/NATS/Subscription.cs @@ -174,7 +174,7 @@ public bool IsValid } } - public virtual void Unsubscribe() + internal void unsubscribe(bool throwEx) { Connection c; lock (mu) @@ -183,11 +183,21 @@ public virtual void Unsubscribe() } if (c == null) - throw new NATSBadSubscriptionException(); + { + if (throwEx) + throw new NATSBadSubscriptionException(); + + return; + } c.unsubscribe(this, 0); } + public virtual void Unsubscribe() + { + unsubscribe(true); + } + public virtual void AutoUnsubscribe(int max) { Connection c = null; diff --git a/NATSUnitTests/NATSUnitTests.csproj b/NATSUnitTests/NATSUnitTests.csproj index 3c58bf3c5..961efb2e7 100755 --- a/NATSUnitTests/NATSUnitTests.csproj +++ b/NATSUnitTests/NATSUnitTests.csproj @@ -22,7 +22,7 @@ true full false - bin\Debug\ + c:\tmp\bin\Debug\ DEBUG;TRACE prompt 4 From 7ec4ad3e36549d17a5d57aac98d938ce1db4c242 Mon Sep 17 00:00:00 2001 From: Colin Sullivan Date: Thu, 26 May 2016 09:43:47 -0600 Subject: [PATCH 2/2] Use bin\Debug for the project output path. --- NATSUnitTests/NATSUnitTests.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NATSUnitTests/NATSUnitTests.csproj b/NATSUnitTests/NATSUnitTests.csproj index 961efb2e7..7802c0250 100755 --- a/NATSUnitTests/NATSUnitTests.csproj +++ b/NATSUnitTests/NATSUnitTests.csproj @@ -22,7 +22,7 @@ true full false - c:\tmp\bin\Debug\ + bin\Debug\ DEBUG;TRACE prompt 4 @@ -123,4 +123,4 @@ --> - \ No newline at end of file +