Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion orleans/ShoppingCart/Grains/InventoryGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@ private async Task PopulateProductCacheAsync()
return;
}

object lockObject = new();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer seeing the lock object be a System.Threading.Lock type.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I didn't know about this explicit lock type. Fixed

await Parallel.ForEachAsync(
state.State,
async (id, _) =>
{
var productGrain = GrainFactory.GetGrain<IProductGrain>(id);
_productCache[id] = await productGrain.GetProductDetailsAsync();
var productDetails = await productGrain.GetProductDetailsAsync();
lock (lockObject)
{
_productCache[id] = productDetails;
}
});
}
}