Skip to content

Instantly share code, notes, and snippets.

@javiercampos
Created February 15, 2022 09:09
Show Gist options
  • Save javiercampos/6e611e10e648c531a553c4494ecd6cb3 to your computer and use it in GitHub Desktop.
Save javiercampos/6e611e10e648c531a553c4494ecd6cb3 to your computer and use it in GitHub Desktop.
Guard
public class Guard
{
private int _guardValue = 0;
public bool Once() => Interlocked.Exchange(ref _guardValue, 1) == 0;
public void Reset() => Interlocked.Exchange(ref _guardValue, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment