Last active
          August 29, 2015 14:07 
        
      - 
      
- 
        Save jaceklaskowski/d57cb87f2e054d4f5b5f to your computer and use it in GitHub Desktop. 
    A working with Observable.from and Future example
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // from https://groups.google.com/d/msg/rxjava/GyVmw-ttbDY/qGHSO5EiEugJ | |
| import rx.lang.scala._ | |
| import scala.concurrent._ | |
| import ExecutionContext.Implicits.global | |
| import java.util.concurrent.TimeUnit | |
| println(s"Current thread: ${Thread.currentThread.getName()}") // run-main-1 | |
| def timeConsumingComputation() = { | |
| TimeUnit.SECONDS.sleep(2) | |
| "time to get up" | |
| } | |
| val f: Future[String] = future { | |
| println(s"Future thread: ${Thread.currentThread.getName()}") // ForkJoinPool-1-worker-5 | |
| timeConsumingComputation() | |
| } | |
| val o = Observable.from(f) | |
| o.subscribe { e => | |
| println(s"Received $e") | |
| println(s"Subscribe thread: ${Thread.currentThread.getName()}") // ForkJoinPool-1-worker-5 | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment