当前位置:网站首页>Simple use of future in Scala
Simple use of future in Scala
2020-11-07 23:58:00 【read】
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)
}
// Through horizon transformation , Give Way Int Have a richer approach
// By inheritance AnyVal, That means this is one 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)
}
}
版权声明
本文为[read]所创,转载请带上原文链接,感谢
边栏推荐
- 使用 Xunit.DependencyInjection 改造测试项目
- See once to understand, graphic single chain table inversion
- Supervisor process management installation and use
- A compilation bug brought by vs2015 Update1 update [existing solutions]
- 2020-11-07:已知一个正整数数组,两个数相加等于N并且一定存在,如何找到两个数相乘最小的两个数?
- Judging whether paths intersect or not by leetcode
- Goland 编写含有template的程序
- On the concurrency of update operation
- The instanceof operator in ecmascript7 specification
- 高并发,你真的理解透彻了吗?
猜你喜欢
随机推荐
Awk implements SQL like join operation
Goland 编写含有template的程序
sed之查找替换
尾-递
微服务的出现和意义的探索
Basic operation of database
2020天翼智能生态博览会中国电信宣布5G SA正式规模商用
These core technology of object-oriented, after you master it, you can have a good interview
获取树形菜单列表
Sentry 安装
awk实现类sql的join操作
ROS学习---远程启动ROS节点
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?
CPP (3) what is cmake
Web安全(三)---CSRF攻击
Web Security (4) -- XSS attack
C语言I博客作业03
C语言I博客作业03
Python image recognition OCR
Python 图片识别 OCR