示例#1
0
        public void Unsubscribe(IValueObserver observer)
        {
            if (observers.Contains(observer))
            {
                return;
            }

            observers.Remove(observer);
            observer.Observable = null;
        }
示例#2
0
        public void Subscribe(IValueObserver observer)
        {
            if (observers.Contains(observer) || observer == null)
            {
                return;
            }

            observers.Add(observer);
            observer.Observable = this;
            observer.UpdateValue();
        }
        public static void ObserveDuration(this IValueObserver observer, Action method)
        {
            var ts = Stopwatch.GetTimestamp();

            try
            {
                method();
            }
            finally
            {
                observer.Observe(GetDuration(ts));
            }
        }
        public static async Task <T> ObserveDurationAsync <T>(this IValueObserver observer, Func <Task <T> > method)
        {
            var ts = Stopwatch.GetTimestamp();

            try
            {
                return(await method().ConfigureAwait(false));
            }
            finally
            {
                observer.Observe(GetDuration(ts));
            }
        }
        public static T ObserveDuration <T>(this IValueObserver observer, Func <T> method)
        {
            var ts = Stopwatch.GetTimestamp();

            try
            {
                return(method());
            }
            finally
            {
                observer.Observe(GetDuration(ts));
            }
        }
示例#6
0
        public async static Task <T> ObserveDurationAsync <T>(this IValueObserver observer, Func <Task <T> > method, DurationUnit unit = DurationUnit.Seconds)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                return(await method().ConfigureAwait(false));
            }
            finally
            {
                observer.Observe(GetDurationValue(stopwatch.Elapsed, unit));
            }
        }
示例#7
0
        public static T ObserveDuration <T>(this IValueObserver observer, Func <T> method, DurationUnit unit = DurationUnit.Seconds)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                return(method());
            }
            finally
            {
                observer.Observe(GetDurationValue(stopwatch.Elapsed, unit));
            }
        }
示例#8
0
        public static void ObserveDuration(this IValueObserver observer, Action method, DurationUnit unit = DurationUnit.Seconds)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                method();
            }
            finally
            {
                observer.Observe(GetDurationValue(stopwatch.Elapsed, unit));
            }
        }
示例#9
0
        public static async Task ObserveDurationAsync(this IValueObserver observer, Func <Task> method, DurationUnit unit)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                await method().ConfigureAwait(false);
            }
            finally
            {
                observer.Observe(GetDurationValue(stopwatch.Elapsed, unit));
            }
        }
示例#10
0
        public static async Task ObserveDurationAsync(this IValueObserver observer, Func <Task> method, DurationUnit unit = DurationUnit.Seconds)
        {
            var ts = Stopwatch.GetTimestamp();

            try
            {
                await method().ConfigureAwait(false);
            }
            finally
            {
                observer.Observe(GetDuration(ts, unit));
            }
        }
示例#11
0
        public static void ObserveDuration(this IValueObserver observer, Action method, DurationUnit unit = DurationUnit.Seconds)
        {
            var ts = Stopwatch.GetTimestamp();

            try
            {
                method();
            }
            finally
            {
                observer.Observe(GetDuration(ts, unit));
            }
        }
示例#12
0
 public static Task <T> ObserveDurationAsync <T>(this IValueObserver observer, Func <Task <T> > method)
 {
     return(ObserveDurationAsync(observer, method, DurationUnit.Seconds));
 }
示例#13
0
 public static T ObserveDuration <T>(this IValueObserver observer, Func <T> method)
 {
     return(ObserveDuration(observer, method, DurationUnit.Seconds));
 }
示例#14
0
 public static void ObserveDuration(this IValueObserver observer, Action method)
 {
     ObserveDuration(observer, method, DurationUnit.Seconds);
 }
示例#15
0
 public static void Observe(this IValueObserver observer, double val, DateTimeOffset timestamp)
 {
     observer.Observe(val, timestamp.ToUnixTime());
 }