view Implab/Diagnostics/Extensions.cs @ 125:f803565868a4 v2

improved performance of promises
author cin
date Thu, 15 Jan 2015 12:09:20 +0300
parents 2573b562e328
children 04d4c92d0f28
line wrap: on
line source

using System;

namespace Implab.Diagnostics {
    public static class Extensions {
        public static IPromise<T> EndLogicalOperation<T>(this IPromise<T> promise) {
            Safe.ArgumentNotNull(promise, "promise");
            var op = TraceContext.Instance.DetachLogicalOperation();

            return promise.On(
                x => {
                    TraceContext.Instance.EnterLogicalOperation(op,true);
                    TraceLog.TraceInformation("promise = {0}", x);
                    TraceLog.EndLogicalOperation();
                    TraceContext.Instance.Leave();
                },
                err =>{
                    TraceContext.Instance.EnterLogicalOperation(op,true);
                    TraceLog.TraceError("promise died {0}", err);
                    TraceLog.EndLogicalOperation();
                    TraceContext.Instance.Leave();
                },
                () => {
                    TraceContext.Instance.EnterLogicalOperation(op,true);
                    TraceLog.TraceInformation("promise cancelled");
                    TraceLog.EndLogicalOperation();
                    TraceContext.Instance.Leave();
                }
            );
        }

        public static IPromise EndLogicalOperation(this IPromise promise) {
            Safe.ArgumentNotNull(promise, "promise");
            var op = TraceContext.Instance.DetachLogicalOperation();

            return promise.On(() => {
                TraceContext.Instance.EnterLogicalOperation(op,true);
                TraceLog.EndLogicalOperation();
                TraceContext.Instance.Leave();
            }, PromiseEventType.All);
        }
    }
}