I am wondering why my Observable
does not produce any element when i am not awaiting its source which is an IAsyncEnumerable
.I am using a Select
over the Observable
, and nothing comes out of it , my code does not execute.
public async IAsyncEnumerable<int> GetAsyncEnumerable()
{
int i=0;
while(true)
{
await Task.Delay(1000);
yield return i++;
}
}
public async Task Run()
{
IAsyncEnumerable<int> enumerable=GetAsyncEnumerable().ToObservable();
await foreach(var elem in enumerable)
{
Console.WriteLine(elem);
}
}
In the above example , the code works and is called while below there is nothing coming out.
public async Task RunObs()
{
IAsyncEnumerable<int> enumerable=GetAsyncEnumerable().ToObservable();
IObservable<int> inputObs = enumerable.ToObservable();
var outputObs = inputObs
.Select(elem=>
{
Console.WriteLine(elem); //does not execute
return elem;
});
}
Do I need to store somewhere the reference to this observable, or how should one do this?