Can I do this or not? It seems Not.
List<Int32> Seq = new List<Int32>() { 5, 6, 7, 8 };
IObservable<Int32> obs_seq = Seq.ToObservable();
obs_seq.Subscribe(
onNext:
async (_seqMember) =>
{
Stopwatch DelayWatc = Stopwatch.StartNew();
await Task.Delay(delay: TimeSpan.FromSeconds(3));
Debug.WriteLine($"{nameof(DelayWatc.Elapsed.TotalMilliseconds)} {DelayWatc.Elapsed.TotalMilliseconds:N1}.");
});
If I put the await after the Write, it prints all of them immediately.
If I put the await before the Write, it never prints anything.
I think nobody is waiting on Subscribe async lambda Task Action.
Somewhere around ten thousand Ticks it decides it can't wait anymore and just throws that lambda into the data hole. Or 5 ten Thousandths of a second.
await Task.Delay(delay: TimeSpan.FromSeconds( (Double) 1E-4 )); will produce 4 stopwatches (.1 millis, and 3 at .0009 millis).
await Task.Delay(delay: TimeSpan.FromSeconds( (Double) 5E-4 )); never produces any output
Strange at best. What's the semantics of this? What's the protocol? SHOULD THIS EVEN COMPILE IF SUBSCRIBE IS NOT GOING TO HONOR AWAIT THE ASYNC LAMBDA
UPDATE
The longer await DOES produce the output, but only after a Thread.Sleep is done, so again, what's the protocol? Should Thread.Sleep block the continuation but the UI message pump thread doesn't?
HOPEFUL FINAL UPDATE
IObservable<Int64> obs_interval = Observable.Interval(period: TimeSpan.FromSeconds(3));
obs_interval.Publish().Connect();
Task T = Task.Run(() =>
{
obs_interval.Latest().First();
});
while (!T.IsCompleted)
{
T.Wait(timeout: TimeSpan.FromMilliseconds(1E2));
Thread.Sleep(timeout: TimeSpan.FromMilliseconds(1E2));
Thread.Yield();
}
This will block each sequence until interval period (+- 1E2 millis), but there seems to be no way to yield the idle time back so as soon as Subscribe method call returns, all threads are blocked.
I feel.like Zip is a good solution but someone explain to me how the observation of the resulting sequence can stall for three seconds without blocking Thread sleep in my code. It must be hardcoded with elevated scheduling because my subscribe lambda is not honored.
What I want to do is put synchronous logic in async lambda that says task wait for nominal for some network latency then if not completed just send another CONGESTION PRODUCING ping on the next clock tick.