Innovenergy_trunk/csharp/app/RemoteSupportConsole/ObservablePipeSource.cs

20 lines
545 B
C#
Raw Normal View History

2023-02-16 12:57:06 +00:00
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)
);
}
}