public static object Ask(ProcessId pid, object message) { if (false) //Process.InMessageLoop) { //return SelfProcess.Actor.ProcessRequest<T>(pid, message); } else { AskActorRes response = null; var handle = new AutoResetEvent(false); var req = new AskActorReq( message, res => { response = res; handle.Set(); }, pid, Self ); var askItem = GetAskItem(); askItem.IfSome( ask => { var inbox = ask.Inbox as ILocalActorInbox; inbox.Tell(req, Self); handle.WaitOne(ProcessConfig.Settings.Timeout); }); if (askItem) { if (response == null) { throw new TimeoutException("Request timed out"); } else { if (response.IsFaulted) { throw response.Exception; } else { return(response.Response); } } } else { throw new Exception("Ask process doesn't exist"); } } }
public static IEnumerable <T> AskMany <T>(IEnumerable <ProcessId> pids, object message, int take) { take = Math.Min(take, pids.Count()); var handle = new CountdownEvent(take); var responses = new List <AskActorRes>(); foreach (var pid in pids) { var req = new AskActorReq( message, res => { responses.Add(res); handle.Signal(); }, pid, Self); Process.tell(AskId, req); } handle.Wait(ProcessConfig.Settings.Timeout); return(responses.Where(r => !r.IsFaulted).Map(r => (T)r.Response)); }