Created
May 20, 2018 21:42
-
-
Save ayende/8244a224568b46a8c74a88c429cf2747 to your computer and use it in GitHub Desktop.
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 string PullAvailableEngineer() | |
{ | |
while (true) | |
{ | |
var get = new GetCompareExchangeValueOperation<List<string>>( | |
key); | |
var getResult = _store.Operations.Send(get); | |
if(getResult == null) | |
{ | |
// no support engineers, wait and retry | |
Thread.Sleep(500); | |
continue; | |
} | |
string engineer = getResult.Value[0]; | |
getResult.Value.RemoveAt(0); | |
CompareExchangeResult<List<string>> result; | |
if (getResult.Value.Count == 0) | |
{ | |
var del = | |
new DeleteCompareExchangeValueOperation<List<string>>( | |
key, | |
getResult.Index); | |
result = _store.Operations.Send(del); | |
} | |
else | |
{ | |
var put = | |
new PutCompareExchangeValueOperation<List<string>>( | |
key, | |
getResult.Value, | |
getResult.Index); | |
result = _store.Operations.Send(put); | |
} | |
if (result.Successful) | |
return engineer; | |
// someone took an available engineer | |
// while we were running, let's try again... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment