RemoveTimestamp Rx (deleted but not forgotten)

Thus, the extremely obsolete Hands-on-Labs (HoL) use the RemoveTimestamp method, which was removed in a later release. I'm not quite sure what his behavior should be. From HoL, this extension method was provided:

 public static IObservable<T> LogTimestampedValues<T>(this IObservable<T> source, Action<Timestamped<T>> onNext) { return source.Timestamp().Do(onNext).RemoveTimestamp(); } 

Is there any replacement, or does anyone know a new operation / expected behavior for this method? Timestamp still exists.

+2
source share
2 answers

You can simply define the extension method yourself by removing the Timestamped wrapper manually by calling Select and returning the Value property from the Timestamped instance:

 public static IObservable<T> LogTimestampedValues<T>(this IObservable<T> source, Action<Timestamped<T>> onNext) { // Validate parameters. if (source == null) throw new ArgumentNullException("source"); if (onNext == null) throw new ArgumentNullException("onNext"); // Timestamp, call action, then unwrap. return source.Timestamp().Do(onNext).Select(t => t.Value); } 

However, to be truly efficient, you really want to define an overload that accepts an IScheduler implementation and calls the Timestamp extension method overload :

 public static IObservable<T> LogTimestampedValues<T>(this IObservable<T> source, Action<Timestamped<T>> onNext, IScheduler scheduler) { // Validate parameters. if (source == null) throw new ArgumentNullException("source"); if (onNext == null) throw new ArgumentNullException("onNext"); if (scheduler == null) throw new ArgumentNullException("scheduler"); // Timestamp, call action, then unwrap. return source.Timestamp(scheduler).Do(onNext).Select(t => t.Value); } 

You want to do this because you may have a specific scheduler that you want to use for logging.

If you do not pass the implementation of IScheduler to, then the original extension method is nothing more than a thin shell using the Do extension method and does not give much value.

+2
source

TA-dah!

 public static IObservable<T> RemoveTimestamp<T>(this IObservable<Timestamped<T>> This) { return This.Select(x => x.Value); } 
+2
source

Source: https://habr.com/ru/post/1487131/


All Articles