Skip to content

Instantly share code, notes, and snippets.

@ayende
Created May 20, 2018 21:42
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 ayende/8244a224568b46a8c74a88c429cf2747 to your computer and use it in GitHub Desktop.
Save ayende/8244a224568b46a8c74a88c429cf2747 to your computer and use it in GitHub Desktop.
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