Esempio n. 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;
 }
Esempio n. 2
0
        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);
        }))
        {
        }
Esempio n. 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);
        }