示例#1
0
    public ICompletes <int> Port()
    {
        if (!_actor.IsStopped)
        {
            Action <IServerRequestResponseChannel> cons1657589136 = __ => __.Port();
            var completes = new BasicCompletes <int>(_actor.Scheduler);
            if (_mailbox.IsPreallocated)
            {
                _mailbox.Send(_actor, cons1657589136, completes, PortRepresentation4);
            }
            else
            {
                _mailbox.Send(
                    new LocalMessage <IServerRequestResponseChannel>(_actor,
                                                                     cons1657589136, completes, PortRepresentation4));
            }

            return(completes);
        }
        else
        {
            _actor.DeadLetters?.FailedDelivery(new DeadLetter(_actor, PortRepresentation4));
        }

        return(null !);
    }
示例#2
0
        public Vlingo.Common.ICompletes <int> Port()
        {
            if (!this.actor.IsStopped)
            {
                Action <Vlingo.Wire.Fdx.Bidirectional.IServerRequestResponseChannel> cons1657589136 = __ => __.Port();
                var completes = new BasicCompletes <int>(this.actor.Scheduler);
                if (this.mailbox.IsPreallocated)
                {
                    this.mailbox.Send(this.actor, cons1657589136, completes, PortRepresentation4);
                }
                else
                {
                    this.mailbox.Send(
                        new LocalMessage <Vlingo.Wire.Fdx.Bidirectional.IServerRequestResponseChannel>(this.actor,
                                                                                                       cons1657589136, completes, PortRepresentation4));
                }

                return(completes);
            }
            else
            {
                this.actor.DeadLetters.FailedDelivery(new DeadLetter(this.actor, PortRepresentation4));
            }

            return(null !);
        }
示例#3
0
    public ICompletes <UserState> WithName(
        Name name)
    {
        if (!_actor.IsStopped)
        {
            Action <IUser> cons128873 = __ => __.WithName(name);
            var            completes  = new BasicCompletes <UserState>(_actor.Scheduler);
            if (_mailbox.IsPreallocated)
            {
                _mailbox.Send(_actor, cons128873, completes, WithNameRepresentation2);
            }
            else
            {
                _mailbox.Send(new LocalMessage <IUser>(_actor,
                                                       cons128873, completes, WithNameRepresentation2));
            }

            return(completes);
        }
        else
        {
            _actor.DeadLetters?.FailedDelivery(new DeadLetter(_actor, WithNameRepresentation2));
        }

        return(null);
    }
        public ICompletes <IEntry> ReadNext(string fromId)
        {
            if (!_actor.IsStopped)
            {
                Action <IStateStoreEntryReader> cons128873 = __ => __.ReadNext(fromId);
                var completes = new BasicCompletes <IEntry>(_actor.Scheduler);
                if (_mailbox.IsPreallocated)
                {
                    _mailbox.Send(_actor, cons128873, completes, ReadNextRepresentation3);
                }
                else
                {
                    _mailbox.Send(
                        new LocalMessage <IStateStoreEntryReader>(_actor,
                                                                  cons128873, completes, ReadNextRepresentation3));
                }

                return(completes);
            }
            else
            {
                _actor.DeadLetters?.FailedDelivery(new DeadLetter(_actor, ReadNextRepresentation3));
            }

            return(null !);
        }
示例#5
0
        public ICompletes <bool> StartUp()
        {
            if (!_actor.IsStopped)
            {
                Action <IServer> cons128873 = __ => __.StartUp();
                var completes = new BasicCompletes <bool>(_actor.Scheduler);
                if (_mailbox.IsPreallocated)
                {
                    _mailbox.Send(_actor, cons128873, completes, StartUpRepresentation7);
                }
                else
                {
                    _mailbox.Send(new LocalMessage <IServer>(_actor, cons128873, completes,
                                                             StartUpRepresentation7));
                }

                return(completes);
            }
            else
            {
                _actor.DeadLetters?.FailedDelivery(new DeadLetter(_actor, StartUpRepresentation7));
            }

            return(null !);
        }
        public ICompletes <string> SeekTo(string id)
        {
            if (!_actor.IsStopped)
            {
                Action <IStateStoreEntryReader> cons128873 = __ => __.SeekTo(id);
                var completes = new BasicCompletes <string>(_actor.Scheduler);
                if (_mailbox.IsPreallocated)
                {
                    _mailbox.Send(_actor, cons128873, completes, SeekToRepresentation7);
                }
                else
                {
                    _mailbox.Send(
                        new LocalMessage <IStateStoreEntryReader>(_actor,
                                                                  cons128873, completes, SeekToRepresentation7));
                }

                return(completes);
            }
            else
            {
                _actor.DeadLetters?.FailedDelivery(new DeadLetter(_actor, SeekToRepresentation7));
            }

            return(null !);
        }
示例#7
0
        public void TestThatFailureOutcomeFailsWhenScheduledInMiddle()
        {
            var andThenValue = 0;
            var failedValue  = -1;
            var completes    = new BasicCompletes <int>(new Scheduler());

            completes
            .AndThen(x => x * x)
            .AndThen(TimeSpan.FromMilliseconds(200), 100, value => andThenValue = value * 2)
            .Otherwise <int>(failedOutcome => failedValue = failedOutcome);

            var thread = new Thread(() =>
            {
                Thread.Sleep(100);
                completes.With(10);
            });

            thread.Start();

            completes.Await();

            Assert.True(completes.HasFailed);
            Assert.Equal(0, andThenValue);
            Assert.Equal(100, failedValue);
        }
示例#8
0
        public void TestThatFailureOutcomeFailsWhenScheduledTimesOut()
        {
            var andThenValue = 0;
            var failedValue  = -1;
            var completes    = new BasicCompletes <int>(_testScheduler);

            completes
            .AndThen(TimeSpan.FromMilliseconds(1), -10, value => value * 2)
            .AndThen(x => andThenValue = 100)
            .Otherwise <int>(failedOutcome => failedValue = failedOutcome);

            var thread = new Thread(() =>
            {
                Thread.Sleep(100);
                completes.With(5);
            });

            thread.Start();

            completes.Await();

            Assert.True(completes.HasFailed);
            Assert.Equal(0, andThenValue);
            Assert.Equal(-10, failedValue);
        }
示例#9
0
 internal AndThenScheduledContinuation(
     BasicCompletes parent,
     BasicCompletes <TAntecedentResult> antecedent,
     TimeSpan timeout,
     Delegate function)
     : this(parent, antecedent, timeout, Optional.Empty <TResult>(), function)
 {
 }
示例#10
0
        public void TestCompletesAfterFluentFunction()
        {
            var completes = new BasicCompletes <int>(0).AndThen(value => value * 2);

            completes.With(5);

            Assert.Equal(10, completes.Outcome);
        }
示例#11
0
        internal override void InnerInvoke(BasicCompletes completedCompletes)
        {
            if (TimedOut.Get() || executed.Get())
            {
                return;
            }

            base.InnerInvoke(completedCompletes);
            executed.Set(true);
        }
        public void TestCompletesAfterSupplier()
        {
            var completes = new BasicCompletes <int>(0);

            completes.After(() => completes.Outcome * 2);

            completes.With(5);

            Assert.Equal(10, completes.Outcome);
        }
示例#13
0
        public void TestThatAwaitTimesOut()
        {
            var completes = new BasicCompletes <int>(_testScheduler);

            var completed = completes.Await(TimeSpan.FromMilliseconds(10));

            completes.With(5);

            Assert.NotEqual(5, completed);
            Assert.Equal(default, completed);
示例#14
0
        public void TestCompletesAfterConsumer()
        {
            int andThenValue = 0;
            var completes    = new BasicCompletes <int>(0);

            completes.AndThen(x => andThenValue = x);

            completes.With(5);

            Assert.Equal(5, andThenValue);
        }
示例#15
0
        public void TestThatExceptionOutcomeInvalidCast()
        {
            var completes = new BasicCompletes <string>(_testScheduler);

            completes
            .AndThen("-100", value => (2 * int.Parse(value)).ToString())
            .AndThen(x => int.Parse(x))
            .Otherwise <int>(x => 1000);

            Assert.Throws <InvalidCastException>(() => completes.With("-100"));
        }
示例#16
0
        internal override bool InnerInvoke(BasicCompletes completedCompletes)
        {
            if (TimedOut.Get() || _executed.Get())
            {
                return(false);
            }

            base.InnerInvoke(completedCompletes);
            _executed.Set(true);
            return(true);
        }
示例#17
0
 internal AndThenScheduledContinuation(
     BasicCompletes?parent,
     BasicCompletes <TAntecedentResult> antecedent,
     TimeSpan timeout,
     Optional <TResult> failedOutcomeValue,
     Delegate function)
     : base(parent, antecedent, failedOutcomeValue, function)
 {
     this.timeout = timeout;
     ClearTimer();
     StartTimer();
 }
示例#18
0
        public void TestCompletesAfterAndThen()
        {
            int andThenValue = 0;
            var completes    = new BasicCompletes <int>(0);

            completes
            .AndThen(value => value * 2)
            .AndThen(x => andThenValue = x);

            completes.With(5);

            Assert.Equal(10, andThenValue);
        }
示例#19
0
 internal AndThenScheduledContinuation(
     Scheduler scheduler,
     BasicCompletes parent,
     BasicCompletes <TAntecedentResult> antecedent,
     TimeSpan timeout,
     Delegate function)
     : base(parent, antecedent, function)
 {
     this.scheduler = scheduler;
     this.timeout   = timeout;
     ClearTimer();
     StartTimer();
 }
        public void TestOutcomeBeforeTimeout()
        {
            int andThenValue = 0;
            var completes    = new BasicCompletes <int>(new Scheduler());

            completes
            .After(() => completes.Outcome * 2, 1000)
            .AndThen(x => andThenValue = x);

            completes.With(5);

            Assert.Equal(10, andThenValue);
        }
示例#21
0
        internal override void InnerInvoke(BasicCompletes completedCompletes)
        {
            if (HasException.Get())
            {
                return;
            }

            if (Action is Action invokableAction)
            {
                invokableAction();
                return;
            }

            if (Action is Action <TResult> invokableActionInput)
            {
                if (completedCompletes is AndThenContinuation <TResult, TResult> andThenContinuation)
                {
                    invokableActionInput(andThenContinuation.FailedOutcomeValue.Get());
                    OutcomeKnown.Set();
                    return;
                }
            }

            if (Action is Func <ICompletes <TAntecedentResult>, TResult> funcCompletes)
            {
                OutcomeValue.Set(funcCompletes(antecedent));
                OutcomeKnown.Set();
                return;
            }

            if (Action is Func <TAntecedentResult, TResult> function)
            {
                if (completedCompletes is AndThenContinuation <TResult, TAntecedentResult> andThenContinuation)
                {
                    OutcomeValue.Set(function(andThenContinuation.FailedOutcomeValue.Get()));
                    OutcomeKnown.Set();
                    return;
                }

                if (completedCompletes is BasicCompletes <TAntecedentResult> otherwiseContinuation)
                {
                    OutcomeValue.Set(function(otherwiseContinuation.FailedOutcomeValue.Get()));
                    OutcomeKnown.Set();
                    return;
                }
            }

            base.InnerInvoke(completedCompletes);

            throw new InvalidCastException("Cannot run 'Otherwise' function. Make sure that expecting type is the same as failedOutcomeValue type");
        }
示例#22
0
        public void TestOutcomeBeforeTimeout()
        {
            int andThenValue = 0;
            var completes    = new BasicCompletes <int>(new Scheduler());

            completes
            .AndThen(TimeSpan.FromMilliseconds(1000), value => value * 2)
            .AndThen(x => andThenValue = x);

            completes.With(5);
            completes.Await <int>(TimeSpan.FromMilliseconds(10));

            Assert.Equal(10, andThenValue);
        }
示例#23
0
        public void TestCompletesAfterAndThenAndThen()
        {
            var andThenValue = string.Empty;
            var completes    = new BasicCompletes <int>(0);

            completes
            .AndThen(value => value * 2)
            .AndThen(value => value.ToString())
            .AndThen(x => andThenValue = x);

            completes.With(5);

            Assert.Equal("10", andThenValue);
        }
示例#24
0
        public void TestCompletesAfterAndThenMessageOut()
        {
            int andThenValue = 0;
            var completes    = new BasicCompletes <int>(0);
            var sender       = new Sender(x => andThenValue = x);

            completes
            .AndThen(value => value * 2)
            .AndThen(x => { sender.Send(x); return(x); });

            completes.With(5);

            Assert.Equal(10, andThenValue);
        }
        internal override bool InnerInvoke(BasicCompletes completedCompletes)
        {
            if (Action is Func <Exception, TResult> function)
            {
                if (completedCompletes is BasicCompletes <TResult> basicCompletes)
                {
                    OutcomeValue.Set(function(basicCompletes.Exception !));
                    return(true);
                }
            }

            Action.DynamicInvoke(completedCompletes.Exception);
            return(true);
        }
        public void TestTimeoutBeforeOutcome()
        {
            int andThenValue = 0;
            var completes    = new BasicCompletes <int>(new Scheduler());

            completes
            .After(() => completes.Outcome * 2, 1, 0)
            .AndThen(x => andThenValue = x);

            Thread.Sleep(1000);
            completes.With(5);

            Assert.NotEqual(10, andThenValue);
            Assert.Equal(0, andThenValue);
        }
示例#27
0
        public void TestThatNestedRecoverFromWithNoExceptionSetsOutput()
        {
            var failureValue = -1;
            var completes    = new BasicCompletes <int>(_testScheduler);

            completes
            .AndThenTo(42, value => Completes.WithSuccess(value * 2).RecoverFrom(e => 0))
            .RecoverFrom(e => failureValue = int.Parse(e.Message));

            completes.With(2);
            completes.Await();

            Assert.False(completes.HasFailed);
            Assert.Equal(-1, failureValue);
            Assert.Equal(4, completes.Outcome);
        }
示例#28
0
        public void TestThatAwaitCompletes()
        {
            var completes = new BasicCompletes <int>(new Scheduler());

            var thread = new Thread(new ThreadStart(() =>
            {
                Thread.Sleep(100);
                completes.With(5);
            }));

            thread.Start();

            var completed = completes.Await <int>();

            Assert.Equal(5, completed);
        }
示例#29
0
        public void TestThatExceptionOutcomeFails()
        {
            int failureValue = -1;
            var completes    = new BasicCompletes <int>(new Scheduler());

            completes
            .AndThen(42, value => value * 2)
            .AndThen <int>(value => throw new ApplicationException((2 * value).ToString()))
            .RecoverFrom(e => failureValue = int.Parse(e.Message));

            completes.With(2);
            completes.Await <int>();

            Assert.True(completes.HasFailed);
            Assert.Equal(8, failureValue);
        }
示例#30
0
        public void TestThatFailureOutcomeFails()
        {
            int andThenValue = -1, failureValue = 0;
            var completes = new BasicCompletes <int>(new Scheduler());

            completes
            .AndThen(-100, value => 2 * value)
            .AndThen(x => andThenValue   = x)
            .Otherwise(x => failureValue = 1000);

            completes.With(-100);
            completes.Await <int>();

            Assert.True(completes.HasFailed);
            Assert.Equal(-1, andThenValue);
            Assert.Equal(1000, failureValue);
        }