예제 #1
0
        private static IObservable <uint> Frames(Auto.ISource autoSource, Mqtt.ISource mqttSource)
        {
            IObservable <uint>            autoFrames           = autoSource.Create().Publish().RefCount();
            IObservable <uint>            mqttFrames           = mqttSource.Create().Publish().RefCount();
            IConnectableObservable <uint> mqttFramesWithReplay = mqttFrames.Replay(1);

            var mqttFrameTimeout = mqttFrames
                                   .Timeout(TimeSpan.FromSeconds(10))
                                   .IgnoreElements()
                                   .Materialize()
                                   .Where(notification => notification.Kind == NotificationKind.OnError);

            var autoFramesUntilMqttFrames = autoFrames.TakeUntil(mqttFrames);
            var mqttFramesUntilTimeout    = mqttFramesWithReplay.TakeUntil(mqttFrameTimeout);

            return(Observable.Using(
                       () => mqttFramesWithReplay.Connect(),
                       _ => Observable.Defer(() => Observable.Concat(autoFramesUntilMqttFrames, mqttFramesUntilTimeout)).Repeat()
                       ));
        }