Skip to content

Instantly share code, notes, and snippets.

@scravy
Created November 19, 2015 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scravy/a066d1aeae6780c97df3 to your computer and use it in GitHub Desktop.
Save scravy/a066d1aeae6780c97df3 to your computer and use it in GitHub Desktop.
import java.util.concurrent.Executors
import scala.concurrent.{ExecutionContext, Future}
object Main extends App {
val executorService = Executors.newFixedThreadPool(5)
implicit val executionContext: ExecutionContext = ExecutionContext.fromExecutorService(executorService)
for {
x <- Future {
Thread.sleep(500)
Right(1)
} recover {
case throwable => Left(throwable)
}
y <- Future {
throw new RuntimeException("yea")
} recover {
case throwable => Left(throwable)
}
z <- Future {
Thread.sleep(100)
Right(2)
} recover {
case throwable => Left(throwable)
}
} yield {
println(x, y, z)
executorService.shutdown()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment