system.reactive - Reactive Extensions: Why does this exit immediately? -


i reading introtorx , i'm having bit of trouble sample code. here sum total of code:

using system; using system.collections.generic; using system.linq; using system.reactive.disposables; using system.reactive.linq; using system.reactive.subjects; using system.text; using system.threading; using system.threading.tasks;  namespace learningreactiveextensions {   public class program   {     static void main(string[] args)     {         var observable = observable.interval(timespan.fromseconds(5));         observable.subscribe(           console.writeline,            () => console.writeline("completed")         );         console.writeline("done");         console.readkey();     }    } } 

if understand book correctly, should write sequence of numbers console, once every 5 seconds forever since never dispose() of sequence.

however, when run code, "done" @ end. no numbers, no "completed", nothing "done".

what doing wrong here?

i assuming haven't had patience wait 5 seconds elapse otherwise have seen code working.

the main idea keep in mind rx observable.subscribe return control calling method immediately. in other words, observable.subscribe not block until results produced. call console.writeline invoked after 5 seconds.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -