Пример #1
0
            public async Task <TryAsyncResult <T> > WaitAsync(CancellationToken token)
            {
                bool isSafeToClose = false;

                try
                {
                    if (!await waitEvent.WaitAsync(token))
                    {
                        if (inputQueue.RemoveReader(this))
                        {
                            isSafeToClose = true;
                            return(TryAsyncResult <T> .FailedResult);
                        }
                        else
                        {
                            await waitEvent.WaitAsync();
                        }
                    }

                    isSafeToClose = true;
                }
                finally
                {
                    if (isSafeToClose)
                    {
                        waitEvent.Dispose();
                    }
                }

                if (exception != null)
                {
                    throw Fx.Exception.AsError(exception);
                }

                return(TryAsyncResult.FromResult(item));
            }
Пример #2
0
            public async Task <(T result, bool success)> WaitAsync(CancellationToken token)
            {
                bool isSafeToClose = false;

                try
                {
                    if (!await waitEvent.WaitAsync(token))
                    {
                        if (inputQueue.RemoveReader(this))
                        {
                            isSafeToClose = true;
                            return(null, false);
                        }
                        else
                        {
                            await waitEvent.WaitAsync();
                        }
                    }

                    isSafeToClose = true;
                }
                finally
                {
                    if (isSafeToClose)
                    {
                        waitEvent.Dispose();
                    }
                }

                if (exception != null)
                {
                    throw Fx.Exception.AsError(exception);
                }

                return(item, true);
            }