Skip to content

)} )}

DisposableAsync.Create(Func) method

Defined in

Type: DisposableAsync Namespace: ReactiveUI.Extensions.Async.Disposables Assembly: ReactiveUI.Extensions.dll

Applies to

net10.0, net10.0-browserwasm1.0, net10.0-desktop1.0, net9.0, net9.0-browserwasm1.0, net9.0-desktop1.0, net8.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.2, net8.0-macos14.5, net8.0-tvos17.2, netstandard2.1, net462, net481

Overloads

  • 1. public static IAsyncDisposable Create(Func<ValueTask> disposeAsync)
  • 2. public static IAsyncDisposable Create<TState>(TState state, Func<TState, ValueTask> disposeAsync)

1. Overload

public static IAsyncDisposable Create(Func<ValueTask> disposeAsync)

View source

Summary: Creates a new asynchronous disposable object that invokes the specified delegate when disposed asynchronously.

Parameters

NameTypeDescription
disposeAsyncFuncA delegate that is called to perform asynchronous disposal logic when the returned object is disposed. Cannot be null.

Returns: IAsyncDisposable -- An IAsyncDisposable instance that invokes the specified delegate when disposed asynchronously.

2. Overload

public static IAsyncDisposable Create<TState>(TState state, Func<TState, ValueTask> disposeAsync)

View source

Summary: Creates a new asynchronous disposable that invokes the specified delegate, passing the supplied state, when disposed asynchronously. Prefer this overload over Create at call sites that would otherwise capture locals or this in the lambda — the state-carrying overload removes the closure object and lets the lambda be declared static.

Type parameters

NameDescription
TStateThe type of the state passed to the dispose delegate.

Parameters

NameTypeDescription
stateTStateThe state forwarded to disposeAsync at dispose time.
disposeAsyncFuncThe dispose delegate. Must not be null.

Returns: IAsyncDisposable -- An IAsyncDisposable instance that invokes the specified delegate when disposed.