Skip to content

,System.IDisposable})} ,System.Action})} ,System.Threading.CancellationToken,System.Threading.Tasks.Task})} ,System.Threading.Tasks.Task})} ,System.Threading.CancellationToken,System.Threading.Tasks.Task{System.IDisposable}})} ,System.Threading.Tasks.Task{System.IDisposable}})} ,System.Threading.CancellationToken,System.Threading.Tasks.Task{System.Action}})} ,System.Threading.Tasks.Task{System.Action}})}

Observable.Create(Func, IDisposable>) method

Defined in

Type: Observable Namespace: System.Reactive.Linq Assembly: System.Reactive.dll

Applies to

netstandard2.0

Overloads

  • 1. public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, IDisposable> subscribe)
  • 2. public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, Action> subscribe)
  • 3. public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, CancellationToken, Task> subscribeAsync)
  • 4. public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, Task> subscribeAsync)
  • 5. public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, CancellationToken, Task<IDisposable>> subscribeAsync)
  • 6. public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, Task<IDisposable>> subscribeAsync)
  • 7. public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, CancellationToken, Task<Action>> subscribeAsync)
  • 8. public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, Task<Action>> subscribeAsync)

1. Overload

public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, IDisposable> subscribe)

Summary: Creates an observable sequence from a specified Subscribe method implementation.

Type parameters

NameDescription
TResultThe type of the elements in the produced sequence.

Parameters

NameTypeDescription
subscribeFunc, IDisposable>Implementation of the resulting observable sequence's Subscribe method.

Returns: IObservable -- The observable sequence with the specified implementation for the Subscribe method.

Remarks

Use of this operator is preferred over manual implementation of the IObservable interface. In case you need a type implementing IObservable rather than an anonymous implementation, consider using the ObservableBase abstract base class.

Exceptions

TypeCondition
System.ArgumentNullExceptionsubscribe is null.

2. Overload

public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, Action> subscribe)

Summary: Creates an observable sequence from a specified Subscribe method implementation.

Type parameters

NameDescription
TResultThe type of the elements in the produced sequence.

Parameters

NameTypeDescription
subscribeFunc, Action>Implementation of the resulting observable sequence's Subscribe method, returning an Action delegate that will be wrapped in an IDisposable.

Returns: IObservable -- The observable sequence with the specified implementation for the Subscribe method.

Remarks

Use of this operator is preferred over manual implementation of the IObservable interface. In case you need a type implementing IObservable rather than an anonymous implementation, consider using the ObservableBase abstract base class.

Exceptions

TypeCondition
System.ArgumentNullExceptionsubscribe is null.

3. Overload

public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, CancellationToken, Task> subscribeAsync)

Summary: Creates an observable sequence from a specified cancellable asynchronous Subscribe method. The CancellationToken passed to the asynchronous Subscribe method is tied to the returned disposable subscription, allowing best-effort cancellation.

Type parameters

NameDescription
TResultThe type of the elements in the produced sequence.

Parameters

NameTypeDescription
subscribeAsyncFunc, CancellationToken, Task>Asynchronous method used to produce elements.

Returns: IObservable -- The observable sequence surfacing the elements produced by the asynchronous method.

Remarks

When a subscription to the resulting sequence is disposed, the CancellationToken that was fed to the asynchronous subscribe function will be signaled.

Exceptions

TypeCondition
System.ArgumentNullExceptionsubscribeAsync is null.

4. Overload

public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, Task> subscribeAsync)

Summary: Creates an observable sequence from a specified asynchronous Subscribe method.

Type parameters

NameDescription
TResultThe type of the elements in the produced sequence.

Parameters

NameTypeDescription
subscribeAsyncFunc, Task>Asynchronous method used to produce elements.

Returns: IObservable -- The observable sequence surfacing the elements produced by the asynchronous method.

Remarks

This operator is especially useful in conjunction with the asynchronous programming features introduced in C# 5.0 and Visual Basic 11.

Exceptions

TypeCondition
System.ArgumentNullExceptionsubscribeAsync is null.

5. Overload

public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, CancellationToken, Task<IDisposable>> subscribeAsync)

Summary: Creates an observable sequence from a specified cancellable asynchronous Subscribe method. The CancellationToken passed to the asynchronous Subscribe method is tied to the returned disposable subscription, allowing best-effort cancellation.

Type parameters

NameDescription
TResultThe type of the elements in the produced sequence.

Parameters

NameTypeDescription
subscribeAsyncFunc, CancellationToken, Task>Asynchronous method used to implement the resulting sequence's Subscribe method.

Returns: IObservable -- The observable sequence with the specified implementation for the Subscribe method.

Remarks

When a subscription to the resulting sequence is disposed, the CancellationToken that was fed to the asynchronous subscribe function will be signaled.

Exceptions

TypeCondition
System.ArgumentNullExceptionsubscribeAsync is null.

6. Overload

public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, Task<IDisposable>> subscribeAsync)

Summary: Creates an observable sequence from a specified asynchronous Subscribe method.

Type parameters

NameDescription
TResultThe type of the elements in the produced sequence.

Parameters

NameTypeDescription
subscribeAsyncFunc, Task>Asynchronous method used to implement the resulting sequence's Subscribe method.

Returns: IObservable -- The observable sequence with the specified implementation for the Subscribe method.

Remarks

This operator is especially useful in conjunction with the asynchronous programming features introduced in C# 5.0 and Visual Basic 11.

Exceptions

TypeCondition
System.ArgumentNullExceptionsubscribeAsync is null.

7. Overload

public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, CancellationToken, Task<Action>> subscribeAsync)

Summary: Creates an observable sequence from a specified cancellable asynchronous Subscribe method. The CancellationToken passed to the asynchronous Subscribe method is tied to the returned disposable subscription, allowing best-effort cancellation.

Type parameters

NameDescription
TResultThe type of the elements in the produced sequence.

Parameters

NameTypeDescription
subscribeAsyncFunc, CancellationToken, Task>Asynchronous method used to implement the resulting sequence's Subscribe method, returning an Action delegate that will be wrapped in an IDisposable.

Returns: IObservable -- The observable sequence with the specified implementation for the Subscribe method.

Remarks

When a subscription to the resulting sequence is disposed, the CancellationToken that was fed to the asynchronous subscribe function will be signaled.

Exceptions

TypeCondition
System.ArgumentNullExceptionsubscribeAsync is null.

8. Overload

public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, Task<Action>> subscribeAsync)

Summary: Creates an observable sequence from a specified asynchronous Subscribe method.

Type parameters

NameDescription
TResultThe type of the elements in the produced sequence.

Parameters

NameTypeDescription
subscribeAsyncFunc, Task>Asynchronous method used to implement the resulting sequence's Subscribe method, returning an Action delegate that will be wrapped in an IDisposable.

Returns: IObservable -- The observable sequence with the specified implementation for the Subscribe method.

Remarks

This operator is especially useful in conjunction with the asynchronous programming features introduced in C# 5.0 and Visual Basic 11.

Exceptions

TypeCondition
System.ArgumentNullExceptionsubscribeAsync is null.