Created
July 17, 2014 10:38
-
-
Save mat-mcloughlin/c44798e38299c0a4b4cd to your computer and use it in GitHub Desktop.
Attempt at reservation pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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