예제 #1
0
        public static IDistributor <T> Trace <T>(
            this IDistributor <T> distributor,
            Action <Lease <T> > onLeaseAcquired  = null,
            Action <Lease <T> > onLeaseReleasing = null)
        {
            if (distributor == null)
            {
                throw new ArgumentNullException("distributor");
            }

            return(Create(
                       start: () =>
            {
                System.Diagnostics.Trace.WriteLine("[Distribute] Start");
                return distributor.Start();
            },
                       onReceive: receive =>
            {
                onLeaseAcquired = onLeaseAcquired ?? TraceOnLeaseAcquired;
                onLeaseReleasing = onLeaseReleasing ?? TraceOnLeaseReleasing;

                // FIX: (Trace) this doesn't do anything if OnReceive was called before Trace, so a proper pipeline model may be better here.
                distributor.OnReceive(async lease =>
                {
                    onLeaseAcquired(lease);
                    await receive(lease);
                    onLeaseReleasing(lease);
                });
            }, stop: () =>
            {
                System.Diagnostics.Trace.WriteLine("[Distribute] Stop");
                return distributor.Stop();
            }, distribute: distributor.Distribute));
        }
예제 #2
0
파일: Smoulder.cs 프로젝트: BWeesy/Smoulder
 public void Start()
 {
     lock (this)
     {
         _loaderCancellationTokenSource      = new CancellationTokenSource();
         _processorCancellationTokenSource   = new CancellationTokenSource();
         _distributorCancellationTokenSource = new CancellationTokenSource();
         Task.Factory.StartNew(() => _loader.Start(_loaderCancellationTokenSource.Token));
         Task.Factory.StartNew(() => _processor.Start(_processorCancellationTokenSource.Token));
         Task.Factory.StartNew(() => _distributor.Start(_distributorCancellationTokenSource.Token));
     }
 }