Skip to content
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

Closed
devantler opened this issue Apr 6, 2020 · 4 comments
Closed

Is it possible to await the HandleAsync method in Effects? #13

devantler opened this issue Apr 6, 2020 · 4 comments

Comments

@devantler
Copy link
Contributor

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?

@mpp
Copy link

mpp commented Apr 6, 2020

I'm not understanding your problem, add an example please.

@devantler
Copy link
Contributor Author

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.

@mpp
Copy link

mpp commented Apr 6, 2020

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.

@devantler
Copy link
Contributor Author

devantler commented Apr 6, 2020

Okay thank you, I will look into Redux more, and try what you propose here. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants