/// <summary> /// Blocks and waits to receive an event of the given types, and /// executes a given action on receiving the event. Returns a /// payload, if there is any, else returns null. /// </summary> /// <returns>Payload</returns> public static Object Receive(params Tuple <Type, Action>[] events) { PSharpRuntime.Assert(Task.CurrentId != null, "Only machines can wait to receive an event."); PSharpRuntime.Assert(PSharpRuntime.TaskMap.ContainsKey((int)Task.CurrentId), "Only machines can wait to receive an event; task {0} does not belong to a machine.", (int)Task.CurrentId); Machine machine = PSharpRuntime.TaskMap[(int)Task.CurrentId]; machine.Receive(events); return(machine.Payload); }
/// <summary> /// Blocks and waits to receive an event of the specified types that satisfy /// the specified predicates. Returns the received event. /// </summary> /// <param name="events">Event types and predicates</param> /// <returns>Received event</returns> public virtual Event Receive(params Tuple <Type, Func <Event, bool> >[] events) { this.Assert(Task.CurrentId != null, "Only machines can " + "wait to receive an event."); this.Assert(this.TaskMap.ContainsKey((int)Task.CurrentId), "Only machines can wait to receive an event; task " + $"{(int)Task.CurrentId} does not belong to a machine."); Machine machine = this.TaskMap[(int)Task.CurrentId]; return(machine.Receive(events)); }
/// <summary> /// Blocks and waits to receive an event of the specified types. /// Returns the received event. /// </summary> /// <param name="eventTypes">Event types</param> /// <returns>Received event</returns> public virtual Event Receive(params Type[] eventTypes) { this.Assert(Task.CurrentId != null, "Only machines can " + "wait to receive an event."); this.Assert(this.TaskMap.ContainsKey((int)Task.CurrentId), "Only machines can wait to receive an event; task " + $"{(int)Task.CurrentId} does not correspond to a machine."); Machine machine = this.TaskMap[(int)Task.CurrentId]; return(machine.Receive(eventTypes)); }