diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/ToUniTaskAsyncEnumerable.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/ToUniTaskAsyncEnumerable.cs index 7867a8b..02523c6 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/ToUniTaskAsyncEnumerable.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/ToUniTaskAsyncEnumerable.cs @@ -248,15 +248,18 @@ namespace Cysharp.Threading.Tasks.Linq return current; } - if (queuedResult.Count != 0) + lock (queuedResult) { - current = queuedResult.Dequeue(); - useCachedCurrent = true; - return current; - } - else - { - return default; // undefined. + if (queuedResult.Count != 0) + { + current = queuedResult.Dequeue(); + useCachedCurrent = true; + return current; + } + else + { + return default; // undefined. + } } } }