/// <summary> /// Reply to an ask with an error /// </summary> /// <remarks> /// This should be used from within a process' message loop only /// </remarks> public static Unit replyError(Exception exception) => InMessageLoop ? ActorContext.CurrentRequest == null ? failwith <Unit>("You can't reply to this message. It wasn't an 'ask'. Use isAsk to confirm whether something is an 'ask' or a 'tell'") : ActorContext.Tell(ActorContext.CurrentRequest.ReplyTo, new ActorResponse( exception, exception.GetType().AssemblyQualifiedName, ActorContext.CurrentRequest.ReplyTo, ActorContext.Self, ActorContext.CurrentRequest.RequestId, true ), ActorContext.Self ) : raiseUseInMsgLoopOnlyException <Unit>(nameof(reply));
/// <summary> /// Reply to an ask /// </summary> /// <remarks> /// This should be used from within a process' message loop only /// </remarks> public static Unit reply <T>(T message) => (message is IReturn) && !((IReturn)message).HasValue ? unit : InMessageLoop ? ActorContext.CurrentRequest == null ? failwith <Unit>("You can't reply to this message. It wasn't an 'ask'. Use isAsk to confirm whether something is an 'ask' or a 'tell'") : ActorContext.Tell( ActorContext.CurrentRequest.ReplyTo, new ActorResponse( message, message.GetType().AssemblyQualifiedName, ActorContext.CurrentRequest.ReplyTo, ActorContext.Self, ActorContext.CurrentRequest.RequestId ), ActorContext.Self ) : raiseUseInMsgLoopOnlyException <Unit>(nameof(reply));
public static Option <UserControlMessage> PreProcessMessage <T>(ProcessId sender, ProcessId self, object message) { if (message == null) { var emsg = $"Message is null for tell (expected {typeof(T)})"; tell(ActorContext.DeadLetters, DeadLetter.create(sender, self, emsg, message)); return(None); } if (message is ActorRequest) { var req = (ActorRequest)message; if (!(req.Message is T) && !(req.Message is Message)) { var emsg = $"Invalid message type for ask (expected {typeof(T)})"; tell(ActorContext.DeadLetters, DeadLetter.create(sender, self, emsg, message)); ActorContext.Tell( sender, new ActorResponse(new Exception($"Invalid message type for ask (expected {typeof(T)})"), typeof(Exception).AssemblyQualifiedName, sender, self, req.RequestId, true ), self ); return(None); } return(Optional((UserControlMessage)message)); } return(new UserMessage(message, sender, sender)); }
/// <summary> /// Send a message to a process /// </summary> /// <param name="pid">Process ID to send to</param> /// <param name="message">Message to send</param> /// <param name="sender">Optional sender override. The sender is handled automatically if you do not provide one.</param> public static Unit tell <T>(ProcessId pid, T message, ProcessId sender = default(ProcessId)) => message is UserControlMessage ? ActorContext.TellUserControl(pid, message as UserControlMessage) : ActorContext.Tell(pid, message, sender);