コード例 #1
0
ファイル: StreamHub.cs プロジェクト: taumuon/SensorDashboard
 private async Task Write(ChannelWriter <SensorReading> writer, SensorReading val, CancellationToken cancellationToken)
 {
     try
     {
         await writer.WriteAsync(val, cancellationToken);
     }
     catch (Exception ex)
     {
         writer.TryComplete(ex);
     }
 }
コード例 #2
0
ファイル: StreamHub.cs プロジェクト: taumuon/SensorDashboard
        // TODO: investigate SignalR 3 pub-sub
        // TODO: dotnet core 3 async enumerables
        public ChannelReader <SensorReading> StartListening(string sensorIdentifier, CancellationToken cancellationToken)
        {
            var channel = Channel.CreateUnbounded <SensorReading>();

            _sensorManager.GetSensorObservable(sensorIdentifier)
            .Subscribe(val =>
            {
                var sensorReading = new SensorReading
                {
                    Value     = val,
                    Timestamp = DateTime.Now
                };
                _ = Write(channel.Writer, sensorReading, cancellationToken);
            }, cancellationToken);


            return(channel.Reader);
        }