dotnet / interactive

.NET Interactive combines the power of .NET with many other languages to create notebooks, REPLs, and embedded coding experiences. Share code, explore data, write, and learn across your apps in ways you couldn't before.
MIT License
2.8k stars 374 forks source link

Subscribe to an Observable.Timer, No output at all #3526

Closed hjy1210 closed 2 months ago

hjy1210 commented 2 months ago

The package and version I'm asking about: Polyglot Notebooks extension v1.0.5208010

Question

Execute the cell with content:

using System.Reactive.Linq;
var timer = Observable.Timer(TimeSpan.FromSeconds(1));
timer.Subscribe(
    x=> Console.WriteLine($"get {x}"), 
    () => Console.WriteLine("completed"));

No ouput at all, only a check symbol appeared with message 1.3s, see image below.

Polyglot_question

jonsequitur commented 2 months ago

This is a little unintuitive but it's working as intended. What's happening is that the cell execution completes before the 1 second has elapsed, and kernel events from that cell execution longer get published.

You can see the output if you prevent the cell execution from completing so quickly:

image

hjy1210 commented 2 months ago

@jonsequitur Thanks a lot.

jonsequitur commented 2 months ago

@hjy1210 You're welcome!