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); }
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; }
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; }
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(); }