当前位置:网站首页>scala 中 Future 的简单使用
scala 中 Future 的简单使用
2020-11-07 23:58:00 【lemos】
scala Future
object MyFuture {
def doWork(i: Int): Int = {
Thread.sleep(3 * 1000)
i
}
def main(args: Array[String]): Unit =
1 to 5 foreach { i =>
val future = Future {
blocking {
doWork(i)
}
}
future onComplete {
case Success(value) => println(value)
case Failure(exception) => println(exception)
}
// 通过视界转换,让 Int 拥有更丰富的方法
// 由于继承了 AnyVal,表明这是一个 value class
/*
implicit final class DurationInt(private val n: Int) extends AnyVal with DurationConversions {
override protected def durationIn(unit: TimeUnit): FiniteDuration = Duration(n.toLong, unit)
}
*/
Await.result(future, 7 seconds)
}
}
版权声明
本文为[lemos]所创,转载请带上原文链接,感谢
https://my.oschina.net/lemos/blog/4707772
边栏推荐
猜你喜欢
随机推荐
About the promotion of the whole stack of engineers, from the introduction to give up the secret arts, do not click in to have a look?
Android Basics - RadioButton (radio button)
Web安全(一)---浏览器同源策略
Cpp(一) 安装CMake
Lay UI left tree Dtree right list table
16. File transfer protocol, vsftpd service
China Telecom announces 5g SA commercial scale in 2020
Writing method of field and field comparison condition in where condition in thinkphpp6
云计算之路-出海记:整一台 aws 免费云服务器
Basic knowledge of C + +
VC6 compatibility and open file crash resolution
Cpp(四) Boost安装及基本使用 for Mac
These core technology of object-oriented, after you master it, you can have a good interview
2020天翼智能生态博览会中国电信宣布5G SA正式规模商用
汇编函数mcall systemstack asmcgocall syscall
Judging whether paths intersect or not by leetcode
看一遍就理解,图解单链表反转
你的主机中的软件中止了一个已建立的连接。解决方法
The emergence and significance of micro service
use Xunit.DependencyInjection Transformation test project