When I run the following code, I get some error:
Error:(15, 25) missing parameter type for expanded function
The argument types of an anonymous function must be fully known. (SLS 8.5)
Expected type was: ?
testFuture onComplete({
^
code:
object TestFuture extends App{
val exe = ExecutionContext.fromExecutor(Executors.newCachedThreadPool())
testFuture onComplete({
case Success((str,i)) =>{
println(str,i)
}
case Failure(e) =>{
e.printStackTrace()
}})(exe)
println(Runtime.getRuntime.availableProcessors())
Thread.sleep(2000)
def testFuture:Future[(String,Int)] = Future[(String,Int)] {
Thread.sleep(1000)
("oh my sky",12)
}(exe)
}
When I decorate 'val exe' with 'implicit' and call the currying function without explicitly using 'exe' like following code, it goes right. Can you tell me why?
object TestFuture extends App{
implicit val exe = ExecutionContext.fromExecutor(Executors.newCachedThreadPool())
testFuture onComplete({
case Success((str,i)) =>{
println(str,i)
}
case Failure(e) =>{
e.printStackTrace()
}})
println(Runtime.getRuntime.availableProcessors())
Thread.sleep(2000)
def testFuture:Future[(String,Int)] = Future[(String,Int)] {
Thread.sleep(1000)
("oh my sky",12)
}
}