workflow-core icon indicating copy to clipboard operation
workflow-core copied to clipboard

Multiple calls to the same event with WaitFor

Open jsolanas7 opened this issue 3 years ago • 1 comments

Hi, i'm trying to wait for the same event based on a condition, the problem is that I can use .WaitFor only 2 times, and then at the third time, the Workflow don't subscribe to the event.

Here is the steps:

builder .StartWith(context => Console.WriteLine("Inicia workflow")) .WaitFor("ValidarEdad", data => "0", data => DateTime.Now) .Then<ValidarEdad>()
.Input(step => step.edad, data => 2);

And the step:

if(edad > 18){ return ExecutionResult.Next(); }else{ output = false; return ExecutionResult.WaitForEvent("ValidarEdad", "0", DateTime.Now); }

And i publish the event with this code:

        host.PublishEvent("ValidarEdad", "0", DateTime.Now);

Have some limit to subscribe in the same event? My idea is when If is false, go back to wait the same event. Thank you!

jsolanas7 avatar Oct 14 '21 13:10 jsolanas7

Ran into same issue today, and made simple extension to solve this issue: public static class ExecutionPointerExtensions { /// <summary> /// Has to be called in case if you want to wait for event after activity was already called from an event /// </summary> /// <param name="executionPointer"></param> public static void ClearEventData(this ExecutionPointer executionPointer) { executionPointer.EventPublished = false; executionPointer.EventName = null; executionPointer.EventKey = null; executionPointer.EventData = null; } }

Has to be called in else condition in your case, so it will be like this: if(edad > 18){ return ExecutionResult.Next(); }else{ output = false; context.ExecutionPointer.ClearEventData(); return ExecutionResult.WaitForEvent("ValidarEdad", "0", DateTime.Now); }

prostopsih avatar Oct 26 '23 11:10 prostopsih