Innovenergy_trunk/csharp/app/RemoteSupportConsole/ObservablePipeSource.cs

20 lines
545 B
C#

using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using CliWrap;
namespace InnovEnergy.RemoteSupportConsole;
public static class ObservablePipeSource
{
// TODO: move to utils?
public static PipeSource AsPipeSource(this IObservable<Byte[]> observable)
{
return PipeSource.Create((destination, cancellationToken) =>
observable
.Select(data => destination.WriteAsync(data, 0, data.Length, cancellationToken))
.ToTask(cancellationToken)
);
}
}