using System; using System.Linq.Expressions; using System.Threading.Tasks; // ReSharper disable UnusedMember.Global namespace Tapeti.Flow { /// /// Provides methods to build an IYieldPoint to indicate if and how Flow should continue. /// public interface IFlowProvider { /// /// Publish a request message and continue the flow when the response arrives. /// The request message must be marked with the [Request] attribute, and the /// Response type must match. Used for asynchronous response handlers. /// /// /// /// /// IYieldPoint YieldWithRequest(TRequest message, Func> responseHandler); /// /// Publish a request message and continue the flow when the response arrives. /// The request message must be marked with the [Request] attribute, and the /// Response type must match. Used for synchronous response handlers. /// /// /// The reason why this requires the extra 'Sync' in the name: one does not simply overload methods /// with Task vs non-Task Funcs. "Ambiguous call". Apparantly this is because a return type /// of a method is not part of its signature,according to: /// http://stackoverflow.com/questions/18715979/ambiguity-with-action-and-func-parameter /// /// /// /// /// /// IYieldPoint YieldWithRequestSync(TRequest message, Func responseHandler); /// /// Create a request builder to publish one or more requests messages. Call Yield on the resulting builder /// to acquire an IYieldPoint. /// IFlowParallelRequestBuilder YieldWithParallelRequest(); /// /// End the flow by publishing the specified response message. Only allowed, and required, when the /// current flow was started by a message handler for a Request message. /// /// /// IYieldPoint EndWithResponse(TResponse message); /// /// End the flow and dispose any state. /// IYieldPoint End(); } /// /// Allows starting a flow outside of a message handler. /// public interface IFlowStarter { /// /// Starts a new flow. /// /// Task Start(Expression>> methodSelector) where TController : class; /// /// Starts a new flow. /// /// Task Start(Expression>>> methodSelector) where TController : class; /// /// Starts a new flow and passes the parameter to the method. /// /// /// Task Start(Expression>> methodSelector, TParameter parameter) where TController : class; /// /// Starts a new flow and passes the parameter to the method. /// /// /// Task Start(Expression>>> methodSelector, TParameter parameter) where TController : class; } /// /// Internal interface. Do not call directly. /// public interface IFlowHandler { /// /// Executes the YieldPoint for the given message context. /// /// /// Task Execute(IFlowHandlerContext context, IYieldPoint yieldPoint); } /// /// Builder to publish one or more request messages and continuing the flow when the responses arrive. /// public interface IFlowParallelRequestBuilder { /// /// Publish a request message and continue the flow when the response arrives. /// Note that the response handler can not influence the flow as it does not return a YieldPoint. /// It can instead store state in the controller for the continuation passed to the Yield method. /// Used for asynchronous response handlers. /// /// /// IFlowParallelRequestBuilder AddRequest(TRequest message, Func responseHandler); /// /// Publish a request message and continue the flow when the response arrives. /// Note that the response handler can not influence the flow as it does not return a YieldPoint. /// It can instead store state in the controller for the continuation passed to the Yield method. /// Used for synchronous response handlers. /// /// /// IFlowParallelRequestBuilder AddRequestSync(TRequest message, Action responseHandler); /// /// Constructs an IYieldPoint to continue the flow when responses arrive. /// The continuation method is called when all responses have arrived. /// Response handlers and the continuation method are guaranteed thread-safe access to the /// controller and can store state. /// Used for asynchronous continuation methods. /// /// IYieldPoint Yield(Func> continuation); /// /// Constructs an IYieldPoint to continue the flow when responses arrive. /// The continuation method is called when all responses have arrived. /// Response handlers and the continuation method are guaranteed thread-safe access to the /// controller and can store state. /// Used for synchronous continuation methods. /// /// IYieldPoint YieldSync(Func continuation); } /// /// Defines if and how the Flow should continue. Construct using any of the IFlowProvider methods. /// public interface IYieldPoint { } }