Ejemplo n.º 1
0
            public static Task <IDisposable> CreateAsync(MyAsyncLock host, int millisecondTimeout)
            {
                var instance = new MyLockInstance(host);

                lock (host)
                {
                    host._locks.Add(instance);

                    // If there aren't any ahead of this
                    if (host._locks.Count == 1)
                    {
                        // Just start it immediately
                        return(Task.FromResult <IDisposable>(instance));
                    }

                    // Otherwise, we need to set up a completion source
                    // which will be triggered after the one before it completes
                    instance._startCompletionSource = new TaskCompletionSource <IDisposable>();

                    if (millisecondTimeout != int.MaxValue)
                    {
                        instance.ConfigureTimeout(millisecondTimeout);
                    }

                    return(instance._startCompletionSource.Task);
                }
            }
Ejemplo n.º 2
0
 public MyLockInstance(MyAsyncLock host)
 {
     _host = host;
 }