mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
26 lines
694 B
C#
26 lines
694 B
C#
using System;
|
|
using System.Reactive.Disposables;
|
|
using System.Reactive.Subjects;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Wabbajack.App.Extensions
|
|
{
|
|
public static class IObservableExtensions
|
|
{
|
|
public static IObservable<TOut> SelectAsync<TIn, TOut>(this IObservable<TIn> input,
|
|
CompositeDisposable disposable,
|
|
Func<TIn, ValueTask<TOut>> func)
|
|
{
|
|
Subject<TOut> returnObs = new();
|
|
|
|
input.Subscribe(x => Task.Run(async () =>
|
|
{
|
|
var result = await func(x);
|
|
returnObs.OnNext(result);
|
|
})).DisposeWith(disposable);
|
|
|
|
return returnObs;
|
|
}
|
|
|
|
}
|
|
} |