view Implab/Diagnostics/Extensions.cs @ 241:c19cee55e85e v2-1

close v2-1 bad idea
author cin
date Thu, 10 Nov 2016 00:31:34 +0300
parents 1b7ebcc52e5a
children 2573b562e328
line wrap: on
line source

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.Then<T>(
                 x => {
                    TraceContext.Instance.EnterLogicalOperation(op,true);
                    TraceLog.TraceInformation("promise = {0}", x);
                    TraceLog.EndLogicalOperation();
                    TraceContext.Instance.Leave();
                    return x;
                },
                err =>{
                    TraceContext.Instance.EnterLogicalOperation(op,true);
                    TraceLog.TraceError("promise died {0}", err);
                    TraceLog.EndLogicalOperation();
                    TraceContext.Instance.Leave();
                    throw new TransientPromiseException(err);
                },
                () => {
                    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.Anyway(() => {
                TraceContext.Instance.EnterLogicalOperation(op,true);
                TraceLog.EndLogicalOperation();
                TraceContext.Instance.Leave();
            });
        }
    }
}