rehansaeed.github.io icon indicating copy to clipboard operation
rehansaeed.github.io copied to clipboard

[Comment] Reactive Extensions (Rx) - Part 5 - Awaiting Observables

Open RehanSaeed opened this issue 5 years ago • 2 comments

https://rehansaeed.com/reactive-extensions-part5-awaiting-observables/

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

David Christensen David Christensen commented on 2017-01-11 12:04:21

In your observable ShowWindow example, I believe there is a (potential) race condition. Shouldn't your code be as shown below? Obviously for this particular example there is unlikely to be a problem, if you are demonstrating a pattern it might be worth correcting it?

public async Task ShowDialog()
{
    Window window = new MyDialogWindow();
    var closing= Observable
        .FromEventPattern(
            h => window.Closed += h,
            h => window.Closed -= h);

    window.Show();
    await closing
        .FirstAsync();
 
    return window.DialogResult;
}

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

Muhammad Rehan Saeed Muhammad Rehan Saeed commented on 2017-01-11 14:25:38

In your observable ShowWindow example, I believe there is a (potential) race condition. Shouldn't your code be as shown below? Obviously for this particular example there is unlikely to be a problem, if you are demonstrating a pattern it might be worth correcting it?

public async Task ShowDialog()
{
    Window window = new MyDialogWindow();
    var closing= Observable
        .FromEventPattern(
            h => window.Closed += h,
            h => window.Closed -= h);

    window.Show();
    await closing
        .FirstAsync();
 
    return window.DialogResult;
}

Corrected, thanks!

RehanSaeed avatar May 12 '20 11:05 RehanSaeed