-
-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to await the HandleAsync method in Effects? #13
Comments
I'm not understanding your problem, add an example please. |
So for example in this code I am using the first Dispatcher to check if a Stakeholder exists, and it has an effect that sets the StakeholderExists to true. But that effect is executed asynchronously, which results in the StakeholderExists to retain its value false, and the DeleteStakeholderAction therefore never being fired. Dispatcher.Dispatch(new CheckStakeholderAction(stakeholder));
if (StakeholderState.Value.StakeholderExists)
{
Dispatcher.Dispatch(new DeleteStakeholderAction(stakeholder));
} I can solve this by using a the bool IsLoading and a while loop like so: Dispatcher.Dispatch(new CheckStakeholderAction(stakeholder));
while(StakeholderState.Value.IsLoading){
//Do Nothing
}
if (StakeholderState.Value.StakeholderExists)
{
Dispatcher.Dispatch(new DeleteStakeholderAction(stakeholder));
} But It would be nice if I could instead await the HandleAsync method in my effect somehow. |
Can't you dispatch that DeleteStakeholderAction at the end of the EffectMethod that handles CheckStakeholderAction? If you need to distinguish if you're "CheckStakeholderAction" for deletion purpose, add a boolean property to the action so the effect knows if it needs to dispatch DeleteStakeholderAction or not. This is the way Flux/Redux works. I suggest you to study that deeper and get more comfortable with the concepts. |
Okay thank you, I will look into Redux more, and try what you propose here. 👍 |
I need the effect to be executed synchronously, but as HandleAsync is called by Fluxor, I am not sure If I can make it so? Is there any way to ensure an action and its effect is finished before going to the nextline where the Dispatcher is used?
The text was updated successfully, but these errors were encountered: