Skip to content

Commit

Permalink
Merge pull request #75 from nats-io/avoid-request-unsub-ex
Browse files Browse the repository at this point in the history
Exception optimization in Connection.request
  • Loading branch information
Colin Sullivan committed May 26, 2016
2 parents 1d3794c + 7ec4ad3 commit c90166a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
7 changes: 1 addition & 6 deletions NATS/Conn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 12 additions & 2 deletions NATS/Subscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public bool IsValid
}
}

public virtual void Unsubscribe()
internal void unsubscribe(bool throwEx)
{
Connection c;
lock (mu)
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion NATSUnitTests/NATSUnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

0 comments on commit c90166a

Please sign in to comment.