SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Subject<bool> subjEvent = new Subject<bool>();
  2. Subject<int> subjValue = new Subject<int>();
  3.  
  4. IScheduler sched = new EventLoopScheduler(ts => new Thread(ts));
  5.  
  6. subjEvent.ObserveOn(sched).Subscribe(
  7.     r =>
  8.         {
  9.             if(r)
  10.             {
  11.                 Console.WriteLine("Connected On: t{0}", Thread.CurrentThread.ManagedThreadId);
  12.  
  13.                 subjValue.ObserveOn(sched).Subscribe(
  14.                     x => Console.WriteLine("Recieved On: t{0}", Thread.CurrentThread.ManagedThreadId));
  15.             }else{
  16.                 Console.WriteLine("Disconnect On: t{0}", Thread.CurrentThread.ManagedThreadId);
  17.             }
  18.         }
  19.     );
  20.  
  21. subjEvent.OnNext(true);
  22. for(int i=0; i< 10; i++)
  23. {
  24.     subjValue.OnNext(i);
  25. }
  26. subjEvent.OnNext(false);
  27. subjValue.OnCompleted();
  28. subjEvent.OnCompleted();
  29.    
  30. var query =
  31.     from b in subjEvent.Do(x =>
  32.         Console.WriteLine("{0}onnected On: t{1}",
  33.             x ? "C" : "Disc",
  34.             Thread.CurrentThread.ManagedThreadId))
  35.     select b ? subjValue : Observable.Empty<int>();
  36.  
  37. query.Switch().Subscribe(x =>
  38.     Console.WriteLine("Recieved On: t{0}",
  39.         Thread.CurrentThread.ManagedThreadId));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top