c# - Understand the flow of control when calling a blocking code from non-blocking block? -



c# - Understand the flow of control when calling a blocking code from non-blocking block? -

i have next code

static void main(string[] args) { //var source = blockingmethod(); var source2 = nonblocking(); source2.subscribe(console.writeline); //source.subscribe(console.writeline); console.readline(); } private static iobservable<string> blockingmethod() { var subject = new replaysubject<string>(); subject.onnext("a"); subject.onnext("b"); subject.oncompleted(); thread.sleep(1000); homecoming subject; } private static iobservable<string> nonblocking() { homecoming observable.create<string>( observable => { observable.onnext("c"); observable.onnext("d"); observable.oncompleted(); //thread.sleep(1000); var source = blockingmethod(); source.subscribe(console.writeline); homecoming disposable.create(() => console.writeline("observer has unsubscribed")); //or can homecoming action //return () => console.writeline("observer has unsubscribed"); }); } }

which prints

c d observer has unsubscribed b

can help me flow of command in program. did seek reading phone call stack etc..but not understand everything.

edit why above output(which assume right) instead of

c d b observer has unsubscribed

the difference in expected behaviour , actual behaviour comes next line:

var subject = new replaysubject<string>();

by default replaysubject uses scheduler.currentthread. it's if declared so:

var subject = new replaysubject<string>(scheduler.currentthread);

when scheduling using current thread actions queued - waiting executing code finish before starts. if want code run need utilize scheduler.immediate so:

var subject = new replaysubject<string>(scheduler.immediate);

does explain sufficiently?

c# asynchronous system.reactive reactive-programming

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -