Reputation: 6220
I'm working with reactive ui and I've run into a problem, essentially in my login method I want to show a progress dialog, attempt the login and then close the dialog and return the final result.
The basic pseudocode of the problem is this:
private IObservable<bool> AttemptLogin(CredentialPair pair)
{
return Dialogs.ShowProgress("logging in", "doing stuff...")
.SelectMany(progressController => DoTheActualLogin(pair))
.Subscribe(boolForWhetherLoginSucceeded =>
{
});
}
ShowProgress
returns an IObservable<ProgressController>
DoTheActualLogIn
returns an IObservable<bool>
The problem is that after performing the login, I need to call the close method against the progress controller.
I can't seem to work out a way of getting the controller further down the sequence.
I'm sure there's a combinator for the sequences that I'm missing / a technique for doing something like this.
Upvotes: 1
Views: 77
Reputation: 18663
Chris' answer is a good one, especially if you have to use the progressController further down the chain. If you just need to clean it up after login you can do:
private IObservable<bool> AttemptLogin(CredentialPair pair)
{
return Dialogs.ShowProgress("logging in", "doing stuff...")
.SelectMany(progressController =>
DoTheActualLogin(pair).Finally(() => progressController.Close()))
.Subscribe(boolForWhetherLoginSucceeded =>
{
});
}
Upvotes: 1
Reputation: 491
I think this is what you're after:
(from progressController in Dialogs.ShowProgress("logging in", "doing stuff...")
from result in DoTheActualLogin(pair)
select new { result, progressController })
.Subscribe(anon => {...}, ex => {...})
Upvotes: 4