/// <summary>
        /// Creates a boolean disposable to own the disposable.
        /// </summary>
        /// <exception cref="ArgumentNullException" />
        public static IBooleanDisposable Create(IBooleanDisposable disposable)
        {
            if (disposable is IBooleanDisposable booleanDisposable)
            {
                return(booleanDisposable);
            }

            return(new SingleDisposable(disposable));
        }
Ejemplo n.º 2
0
        public static void TestTryDisposeExecuteAtMostOnce(IBooleanDisposable d)
        {
            d.IsDisposed.Is(false);

            var count = 0;

            Parallel.For(0, 100, i =>
            {
                if (d.TryDispose())
                {
                    Interlocked.Increment(ref count);
                }
            });

            count.Is(1);
            d.IsDisposed.Is(true);
        }