예제 #1
0
 public static Polyface IsThrottle(this Polyface root, int maxConcurrency)
 {
     Condition.Requires(root).IsNotNull();
     var composited = new NaturalThrottle(maxConcurrency);
     root.Is(composited);
     return root;
 }
예제 #2
0
파일: Tests.cs 프로젝트: Piirtaa/Decoratid
        public ThrottleTest()
            : base(LogicOf <Nothing> .New((x) =>
        {
            NaturalThrottle.New(1);

            int count = 0;
            var logic = Logic.New(() =>
            {
                count++;
                Thread.Sleep(2000);
            });

            var throttled = logic.Throttle(1);

            Action act1 = new Action(() => { throttled.Perform(); });
            Action act2 = new Action(() => { throttled.Perform(); });
            act1.EnqueueToThreadPool();
            act2.EnqueueToThreadPool();
            Thread.Sleep(1000);
            Condition.Requires(count).IsEqualTo(1);
            Thread.Sleep(1000);
            Condition.Requires(count).IsEqualTo(1);
            Thread.Sleep(2000);
            Condition.Requires(count).IsEqualTo(2);
        }))
        {
        }
예제 #3
0
        public static Polyface IsThrottle(this Polyface root, int maxConcurrency)
        {
            Condition.Requires(root).IsNotNull();
            var composited = new NaturalThrottle(maxConcurrency);

            root.Is(composited);
            return(root);
        }