Skip to content

Instantly share code, notes, and snippets.

@Im5tu
Created January 7, 2018 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Im5tu/40dfcbc80e12902ed3af6d3b8d8c8ced to your computer and use it in GitHub Desktop.
Save Im5tu/40dfcbc80e12902ed3af6d3b8d8c8ced to your computer and use it in GitHub Desktop.
DisposeCorrelation
private class DisposeCorrelation : IDisposable
{
private readonly AsyncLocal<Stack<Guid>> _localStack;
public DisposeCorrelation(AsyncLocal<Stack<Guid>> localStack)
{
_localStack = localStack;
}
public void Dispose()
{
var stack = _localStack.Value ?? new Stack<Guid>();
if(stack.Count > 0)
stack.Pop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment