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

How do I wait for interconnected commands to end? #24

Closed
hasimyerlikaya opened this issue Aug 3, 2019 · 5 comments
Closed

How do I wait for interconnected commands to end? #24

hasimyerlikaya opened this issue Aug 3, 2019 · 5 comments

Comments

@hasimyerlikaya
Copy link

I use interconnected commands to perform a systematic job. For example, one command receives data from the server, the other command prepares the data, and the last command updates the interface.

Screen Shot 2019-08-03 at 15 44 04

I want to show loading on the screen until these three commands are finished. I can do it with WidgetSelector for a single command. But I want to wait until more than one command is finished.

Screen Shot 2019-08-03 at 15 51 03

How can I make it happen?

@escamoteur
Copy link
Collaborator

@anaisbetts could you please have look at this I'm on vacation

@anaisbetts
Copy link
Contributor

anaisbetts commented Aug 9, 2019

If they all chain, just listen to the last one. If not, use RxDart's merge followed by last

@hasimyerlikaya
Copy link
Author

@anaisbetts @escamoteur

I know I need to listen to the last command to get data. But that's not what I'm asking. I want to show loading indicator on the screen until all commands are finished.

The Loading indicator will appear when the first command runs and will disappear when the last command finishes its job. That's exactly what I want.

I can do this in various ways. But I wanted to ask if there is a practical method. Maybe WidgetSelector or other widgets can be customized for it.

@dluksza
Copy link

dluksza commented Aug 15, 2019

Do you really need to send/initialize all of those three commands?

I'm guessing you're not sending all of those events from UI. If I understand you correctly you want send event to start first command. Then when first command finishes, start second one and after it finish start third one, and finally update UI, am I right?

If yes, then you actually don't need three commands! You need one command and a manager/stream that will do the work of calling services and passing the data around. Create a manager that will combine work from those three commands in one Future or Stream then use it to create RxCommand.

Hope that helps.

@escamoteur
Copy link
Collaborator

If the commands are only called from other commands and are in the same class it doesn't make sense to split them if they are only called sequentially.
If you would call command2 async at the beginning of command 1 it would be different.
In this case you could just use rx to combine the the isExecuting with combineLatest.

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

4 participants