当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- golang 匿名结构体成员,具名结构体成员,继承,组合
- 什么你的电脑太渣?这几招包你搞定! (Win10优化教程)
- November 07, 2020: given an array of positive integers, the sum of two numbers equals N and must exist. How to find the two numbers with the smallest multiplication?
- Python image recognition OCR
- 在Ubuntu上体验最新版本EROFS
- Qt混合Python开发技术:Python介绍、混合过程和Demo
- leetcode之判断路径是否相交
- Idea - the. IML file was not automatically generated by the project
- 关于晋升全栈工程师,从入门到放弃的神功秘籍,不点进来看一看?
- WPF personal summary on drawing
猜你喜欢
Ladongo open source full platform penetration scanner framework
See once to understand, graphic single chain table inversion
Qt混合Python开发技术:Python介绍、混合过程和Demo
计组-总线通信控制之异步串行通信的数据传输
laravel8更新之维护模式改进
团灭 LeetCode 股票买卖问题
获取树形菜单列表
Wanxin Finance
Idea - the. IML file was not automatically generated by the project
在Ubuntu上体验最新版本EROFS
随机推荐
来自不同行业领域的50多个对象检测数据集
Awk implements SQL like join operation
你的主机中的软件中止了一个已建立的连接。解决方法
到底选openstack还是vmware?
The instanceof operator in ecmascript7 specification
c# 表达式树(一)
C++在C的基础上改进了哪些细节
Wechat applet request reported 400 error @ requestbody failed to receive
Judging whether paths intersect or not by leetcode
接口
Introduction to ucgui
Adobe Lightroom / LR 2021 software installation package (with installation tutorial)
Basic knowledge of C + +
delphi10的rest.json与system.json的踩坑
云计算之路-出海记:整一台 aws 免费云服务器
The emergence and significance of micro service
学习Scala IF…ELSE 语句
sed之查找替换
Static + code block + polymorphism + exception
Qt混合Python开发技术:Python介绍、混合过程和Demo