// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. #nullable enable using System; using System.Threading.Tasks; namespace osu.Game.Utils { /// /// A chain of s that run sequentially. /// public class TaskChain { private readonly object currentTaskLock = new object(); private Task? currentTask; /// /// Adds a new task to the end of this . /// /// The task creation function. /// The awaitable . public Task Add(Func taskFunc) { lock (currentTaskLock) { currentTask = currentTask == null ? taskFunc() : currentTask.ContinueWith(_ => taskFunc()).Unwrap(); return currentTask; } } } }