Esempio n. 1
0
        public static Producer <T> RegulatePressure <T, TFeedback>(this Producer <T> producer, int limit, Producer <TFeedback> feedback, Func <int, int, TFeedback, int>?regulate = null, ChannelOptions?options = null)
        {
            regulate ??= (pressure, _2, _3) => pressure - 1;
            var actor = new PressureControlActor <T, TFeedback>(limit, regulate);

            producer.LinkTo(actor.Inbox, options);
            feedback.LinkTo(actor.Feedback, options);
            actor.Start();
            return(actor.Outbox);
        }
Esempio n. 2
0
        public async Task RegulatePressure_WithLimitAndFeedback_ShouldThrowOnNegativePressure()
        {
            var actor = new PressureControlActor <int, int>(1, (_1, _2, _3) => - 2);

            using var producer = new Producer <int>();
            using var feedback = new Producer <int>();
            using var consumer = new Consumer <int>();

            producer.LinkTo(actor.Inbox);
            feedback.LinkTo(actor.Feedback);
            actor.Outbox.LinkTo(consumer);

            await producer.WriteAsync(1);

            await producer.WriteAsync(2);

            await feedback.WriteAsync(1);

            actor.Start();

            await Assert.ThrowsAsync <Exception>(async() => await actor.Completion);
        }