示例#1
0
        private static IDistributor <int> CreateDistributor(Func <Lease <int>, Task> onReceive = null)
        {
            var distributor = new InMemoryDistributor <int>(new[]
            {
                new Leasable <int>(1, "1")
            }, "").Trace();

            distributor.OnReceive(onReceive ?? (async _ => { }));

            return(distributor);
        }
 protected override IDistributor <int> CreateDistributor(
     Func <Lease <int>, Task> onReceive = null,
     Leasable <int>[] leasables         = null,
     int maxDegreesOfParallelism        = 5,
     string name           = null,
     TimeSpan?waitInterval = null,
     string pool           = null)
 {
     distributor = new InMemoryDistributor <int>(
         leasables ?? DefaultLeasable,
         pool ?? DateTimeOffset.UtcNow.Ticks.ToString(),
         maxDegreesOfParallelism,
         waitInterval,
         DefaultLeaseDuration);
     if (onReceive != null)
     {
         distributor.OnReceive(onReceive);
     }
     return(distributor);
 }
示例#3
0
        public async Task Distributor_Trace_default_behavior_can_be_overridden()
        {
            Lease <int> leaseAcquired = null;
            Lease <int> leaseReleased = null;

            var distributor1 = new InMemoryDistributor <int>(new[]
            {
                new Leasable <int>(1, "1")
            }, "").Trace(
                onLeaseAcquired: l => { leaseAcquired = l; },
                onLeaseReleasing: l => { leaseReleased = l; });

            distributor1.OnReceive((async _ => { }));
            var distributor = distributor1;

            await distributor.Distribute(1);

            leaseAcquired.Should().NotBeNull();
            leaseReleased.Should().NotBeNull();
        }
 protected override IDistributor<int> CreateDistributor(
     Func<Lease<int>, Task> onReceive = null,
     Leasable<int>[] leasables = null,
     int maxDegreesOfParallelism = 5,
     string name = null,
     TimeSpan? waitInterval = null,
     string pool = null)
 {
     distributor = new InMemoryDistributor<int>(
         leasables ?? DefaultLeasable,
         pool ?? DateTimeOffset.UtcNow.Ticks.ToString(),
         maxDegreesOfParallelism,
         waitInterval,
         DefaultLeaseDuration);
     if (onReceive != null)
     {
         distributor.OnReceive(onReceive);
     }
     return distributor;
 }
示例#5
0
        private static IDistributor<int> CreateDistributor(Func<Lease<int>, Task> onReceive = null)
        {
            var distributor = new InMemoryDistributor<int>(new[]
            {
                new Leasable<int>(1, "1")
            }, "").Trace();

            distributor.OnReceive(onReceive ?? (async _ => { }));

            return distributor;
        }
示例#6
0
        public async Task Distributor_Trace_default_behavior_can_be_overridden()
        {
            Lease<int> leaseAcquired = null;
            Lease<int> leaseReleased = null;

            var distributor1 = new InMemoryDistributor<int>(new[]
            {
                new Leasable<int>(1, "1")
            }, "").Trace(
                onLeaseAcquired: l => { leaseAcquired = l; },
                onLeaseReleasing: l => { leaseReleased = l; });

            distributor1.OnReceive((async _ => { }));
            var distributor = distributor1;

            await distributor.Distribute(1);

            leaseAcquired.Should().NotBeNull();
            leaseReleased.Should().NotBeNull();
        }