Exemple #1
0
 /// <summary>
 /// Create N child processes.
 /// The name provided will be used as a basis to generate the child names.  Each child will
 /// be named "name-index" where index starts at zero.
 /// If this is called from within a process' message loop
 /// then the new processes will be a children of the current process.  If it is called from
 /// outside of a process, then they will be made a child of the root 'user' process.
 /// </summary>
 /// <typeparam name="S">State type</typeparam>
 /// <typeparam name="T">Type of messages that the child-process can accept</typeparam>
 /// <param name="Spec">Map of IDs and State for generating child workers</param>
 /// <param name="Name">Name of the child-process</param>
 /// <param name="Inbox">Function that is the process</param>
 /// <param name="Flags">Process flags</param>
 /// <param name="Strategy">Failure supervision strategy</param>
 /// <param name="Terminated">Message function to call when a Process [that this Process
 /// watches] terminates</param>
 /// <returns>ProcessId IEnumerable</returns>
 public static IEnumerable <ProcessId> spawnMany <S, T>(
     ProcessName Name,
     Map <int, Func <S> > Spec,
     Func <S, T, S> Inbox,
     ProcessFlags Flags = ProcessFlags.Default,
     State <StrategyContext, Unit> Strategy = null,
     int MaxMailboxSize = ProcessSetting.DefaultMailboxSize,
     Func <S, ProcessId, S> Terminated = null
     ) =>
 Map.map(Spec, (id, state) => ActorContext.ActorCreate(ActorContext.SelfProcess, $"{Name}-{id}", Inbox, state, Terminated, Strategy, Flags, MaxMailboxSize, false)).Values.ToList();
 /// <summary>
 /// Create N child processes.
 /// The name provided will be used as a basis to generate the child names.  Each child will
 /// be named "name-index" where index starts at zero.
 /// If this is called from within a process' message loop
 /// then the new processes will be a children of the current process.  If it is called from
 /// outside of a process, then they will be made a child of the root 'user' process.
 /// </summary>
 /// <typeparam name="S">State type</typeparam>
 /// <typeparam name="T">Type of messages that the child-process can accept</typeparam>
 /// <param name="spec">Map of IDs and State for generating child workers</param>
 /// <param name="name">Name of the child-process</param>
 /// <param name="messageHandler">Function that is the process</param>
 /// <param name="flags">Process flags</param>
 /// <returns>ProcessId IEnumerable</returns>
 public static IEnumerable <ProcessId> spawnN <S, T>(ProcessName name, Map <int, Func <S> > spec, Func <S, T, S> messageHandler, ProcessFlags flags = ProcessFlags.Default) =>
 Map.map(spec, (id, state) => ActorContext.ActorCreate(ActorContext.SelfProcess, name + "-" + id, messageHandler, state, flags)).Values.ToList();
 /// <summary>
 /// Spawns a new process with N worker processes, each message is sent to one worker
 /// process in a round robin fashion.
 /// </summary>
 /// <typeparam name="T">Message type</typeparam>
 /// <param name="name">Delegator process name</param>
 /// <param name="spec">Map of IDs and State for generating child workers</param>
 /// <param name="messageHandler">Worker message handler</param>
 /// <param name="flags">Process flags</param>
 /// <returns>Process ID of the delegator process</returns>
 public static ProcessId spawnRoundRobin <S, T>(ProcessName name, Map <int, Func <S> > spec, Func <S, T, S> messageHandler, ProcessFlags flags = ProcessFlags.Default) =>
 spawn <Unit, T>(name, () => ignore(Map.map(spec, (id, state) => ActorContext.ActorCreate(ActorContext.SelfProcess, "worker-" + id, messageHandler, state, flags))), (_, msg) => HandleNoChild(() => fwdNextChild(msg)), flags);
Exemple #4
0
 public static IImmutableDictionary <K, T> choose <K, T>(IImmutableDictionary <K, T> map, Func <K, T, Option <T> > selector) =>
 Map.map(filter(Map.map(map, selector), t => t.IsSome), t => t.Value);