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

AffRxExtensions.Consume blocks the waiting thread on IObservable's completion #1283

Open
aloslider opened this issue Nov 24, 2023 · 0 comments · May be fixed by #1284
Open

AffRxExtensions.Consume blocks the waiting thread on IObservable's completion #1283

aloslider opened this issue Nov 24, 2023 · 0 comments · May be fixed by #1284
Labels

Comments

@aloslider
Copy link

aloslider commented Nov 24, 2023

I'm learning the ways how to handle observables with this library. This is an example I get a problem with:

using System.Reactive.Linq;
using LanguageExt;
using LanguageExt.Sys;
using LanguageExt.Sys.Live;
// Generates numbers from 0 to 4 each 500ms
var obs =
    Observable.Generate(
        initialState: 0,
        condition: x => x < 5,
        iterate: x => x + 1,
        resultSelector: x => x,
        timeSelector: _ => TimeSpan.FromSeconds(0.5));
await obs.Consume(x => Console<Runtime>.writeLine($"{x}").ToAff()).Run(Runtime.New());

Output: "01234" with a blocked console window, when expected a closed one.

It seems that AutoResetEvent.WaitOne() blocks the thread forever, as there's no onCompleted handler passed when subscribing to the observable.
If it's just me doing something wrong, then I would be glad to be pointed to how to work with observables (specifically, the ones created from C# events to handle them when they are fired).

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

Successfully merging a pull request may close this issue.

2 participants