Code RoomAsync call blocks all threads
HardPrep Room Coding #2210

Async call blocks all threads

Code reviewConcurrencySenior–Staff~31 min

Review this C# cache that serializes refreshes with a lock.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 31 min
Mark a line and say what kind of problem it is.0 findings
1private readonly object _gate = new object();
2private Data _data;
3 
4public async Task<Data> GetAsync() {
5 lock (_gate) {
6 if (_data != null) return _data;
7 _data = await FetchFromNetworkAsync(); // refresh
8 return _data;
9 }
10}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.