MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.21k stars 21.37k forks source link

Incorrect example given for executing critical sections of Durable entities #95840

Open ashgit24 opened 2 years ago

ashgit24 commented 2 years ago

Hi Its mentioned in the critical section rules that "Critical sections can signal only entities they haven't locked." but in the example given, the below lines would fail to execute inside the lock. await sourceProxy.Add(-transferAmount); await destinationProxy.Add(transferAmount);

using (await context.LockAsync(sourceEntity, destinationEntity))
{
    ICounter sourceProxy = 
        context.CreateEntityProxy<ICounter>(sourceEntity);
    ICounter destinationProxy =
        context.CreateEntityProxy<ICounter>(destinationEntity);

    int sourceBalance = await sourceProxy.Get();

    if (sourceBalance >= transferAmount)
    {
        await sourceProxy.Add(-transferAmount);
        await destinationProxy.Add(transferAmount);

        // the transfer succeeded
        return true;
    }
    else
    {
        // the transfer failed due to insufficient funds
        return false;
   }

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

MonikaReddy-MSFT commented 2 years ago

@ashgit24 - Thanks for bringing this to our attention. I'm going to assign this to the document author so they can update the document accordingly.

cgillum commented 2 years ago

@sebastianburckhardt can you take a look?