Akka.Routing.ScatterGatherFirstCompletedRoutees.Send C# (CSharp) Method

Send() public method

Sends a message to the collection of routees.
public Send ( object message, IActorRef sender ) : void
message object The message that is being sent.
sender IActorRef The actor sending the message.
return void
        public override void Send(object message, IActorRef sender)
        {
            var tcs = new TaskCompletionSource<object>();

            if (_routees.IsNullOrEmpty())
            {
                tcs.SetResult(new Status.Failure(new AskTimeoutException("Timeout due to no routess")));
            }
            else
            {
                var tasks = _routees
                    .Select(routee => routee.Ask(message, _within))
                    .ToList();

                Task
                    .WhenAny(tasks)
                    .ContinueWith(task =>
                    {
                        if (task.Result.IsCanceled)
                        {
                            tcs.SetResult(new Status.Failure(new AskTimeoutException($"Timeout after {_within.TotalSeconds} seconds")));
                        }
                        else if (task.Result.IsFaulted)
                        {
                            tcs.SetResult(new Status.Failure(task.Result.Exception));
                        }
                        else
                        {
                            tcs.SetResult(task.Result.Result);
                        }
                    });
            }

            tcs.Task.PipeTo(sender);
        }
    }
ScatterGatherFirstCompletedRoutees