1
0
Эх сурвалжийг харах

Adding Empty, Never, Return, and Throw.

Bart De Smet 8 жил өмнө
parent
commit
c7aa032777

+ 20 - 0
AsyncRx.NET/System.Reactive.Async/System/Reactive/Linq/Operators/Empty.cs

@@ -0,0 +1,20 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the Apache 2.0 License.
+// See the LICENSE file in the project root for more information. 
+
+using System.Reactive.Disposables;
+
+namespace System.Reactive.Linq
+{
+    partial class AsyncObservable
+    {
+        public static IAsyncObservable<T> Empty<T>()
+        {
+            return Create<T>(async observer =>
+            {
+                await observer.OnCompletedAsync().ConfigureAwait(false);
+                return AsyncDisposable.Nop;
+            });
+        }
+    }
+}

+ 17 - 0
AsyncRx.NET/System.Reactive.Async/System/Reactive/Linq/Operators/Never.cs

@@ -0,0 +1,17 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the Apache 2.0 License.
+// See the LICENSE file in the project root for more information. 
+
+using System.Reactive.Disposables;
+using System.Threading.Tasks;
+
+namespace System.Reactive.Linq
+{
+    partial class AsyncObservable
+    {
+        public static IAsyncObservable<T> Never<T>()
+        {
+            return Create<T>(observer => Task.FromResult(AsyncDisposable.Nop));
+        }
+    }
+}

+ 21 - 0
AsyncRx.NET/System.Reactive.Async/System/Reactive/Linq/Operators/Return.cs

@@ -0,0 +1,21 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the Apache 2.0 License.
+// See the LICENSE file in the project root for more information. 
+
+using System.Reactive.Disposables;
+
+namespace System.Reactive.Linq
+{
+    partial class AsyncObservable
+    {
+        public static IAsyncObservable<T> Return<T>(T value)
+        {
+            return Create<T>(async observer =>
+            {
+                await observer.OnNextAsync(value).ConfigureAwait(false);
+                await observer.OnCompletedAsync().ConfigureAwait(false);
+                return AsyncDisposable.Nop;
+            });
+        }
+    }
+}

+ 23 - 0
AsyncRx.NET/System.Reactive.Async/System/Reactive/Linq/Operators/Throw.cs

@@ -0,0 +1,23 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the Apache 2.0 License.
+// See the LICENSE file in the project root for more information. 
+
+using System.Reactive.Disposables;
+
+namespace System.Reactive.Linq
+{
+    partial class AsyncObservable
+    {
+        public static IAsyncObservable<T> Throw<T>(Exception error)
+        {
+            if (error == null)
+                throw new ArgumentNullException(nameof(error));
+
+            return Create<T>(async observer =>
+            {
+                await observer.OnErrorAsync(error).ConfigureAwait(false);
+                return AsyncDisposable.Nop;
+            });
+        }
+    }
+}