예제 #1
0
        private static TSource LastOrDefaultInternal <TSource>(IObservable <TSource> source, bool throwOnEmpty)
        {
            using var consumer = new LastBlocking <TSource>();

            using (source.Subscribe(consumer))
            {
                consumer.Wait();
            }

            consumer._error?.Throw();

            if (throwOnEmpty && !consumer._hasValue)
            {
                throw new InvalidOperationException(Strings_Linq.NO_ELEMENTS);
            }

            return(consumer._value);
        }
예제 #2
0
        private static TSource LastOrDefaultInternal <TSource>(IObservable <TSource> source, bool throwOnEmpty)
        {
            using (var consumer = new LastBlocking <TSource>())
            {
                using (var d = source.Subscribe(consumer))
                {
                    consumer.SetUpstream(d);

                    if (consumer.CurrentCount != 0)
                    {
                        consumer.Wait();
                    }
                }

                consumer._error.ThrowIfNotNull();

                if (throwOnEmpty && !consumer._hasValue)
                {
                    throw new InvalidOperationException(Strings_Linq.NO_ELEMENTS);
                }
                return(consumer._value);
            }
        }