Skip to content

Instantly share code, notes, and snippets.

@mat-mcloughlin
Created July 17, 2014 10:38
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 mat-mcloughlin/c44798e38299c0a4b4cd to your computer and use it in GitHub Desktop.
Save mat-mcloughlin/c44798e38299c0a4b4cd to your computer and use it in GitHub Desktop.
Attempt at reservation pattern
public class FooReserver
{
private readonly int reserveFor;
public static List<string> ReservedFoos = new List<string>();
public FooReserver(int reserveFor)
{
this.reserveFor = reserveFor;
}
public void Reserve(string fooName)
{
if (ReservedFoos.Contains(fooName))
{
throw new NameIsReservedException();
}
ReservedFoos.Add(fooName);
Task.Run(() =>
{
Task.Delay(this.reserveFor);
ReservedFoos.Remove(fooName);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment