Timestamp.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Reactive.Concurrency;
  5. using System.Threading.Tasks;
  6. namespace System.Reactive.Linq
  7. {
  8. partial class AsyncObservable
  9. {
  10. public static IAsyncObservable<Timestamped<TSource>> Timestamp<TSource>(this IAsyncObservable<TSource> source, IClock clock)
  11. {
  12. if (source == null)
  13. throw new ArgumentNullException(nameof(source));
  14. if (clock == null)
  15. throw new ArgumentNullException(nameof(clock));
  16. return Create<Timestamped<TSource>>(observer => source.SubscribeAsync(AsyncObserver.Timestamp(observer, clock)));
  17. }
  18. }
  19. partial class AsyncObserver
  20. {
  21. public static IAsyncObserver<TSource> Timestamp<TSource>(IAsyncObserver<Timestamped<TSource>> observer, IClock clock)
  22. {
  23. if (observer == null)
  24. throw new ArgumentNullException(nameof(observer));
  25. if (clock == null)
  26. throw new ArgumentNullException(nameof(clock));
  27. return Select<TSource, Timestamped<TSource>>(observer, x => new Timestamped<TSource>(x, clock.Now));
  28. }
  29. }
  30. }