当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
猜你喜欢

Idea - the. IML file was not automatically generated by the project

Qt混合Python开发技术:Python介绍、混合过程和Demo

Android Basics - RadioButton (radio button)

Cryptography - Shangsi Valley

【解决方案】分布式定时任务解决方案

Go sending pin and email

China Telecom announces 5g SA commercial scale in 2020

状态压缩:对动态规划进行降维打击

VC6兼容性及打开文件崩溃问题解决

delphi10的rest.json与system.json的踩坑
随机推荐
Adobe Prelude /Pl 2020软件安装包(附安装教程)
Cpp(二) 创建Cpp工程
Everything is 2020, LINQ query you are still using expression tree
Web安全(三)---CSRF攻击
LadonGo开源全平台渗透扫描器框架
使用jsDelivr加速你的网站
Wechat applet request reported 400 error @ requestbody failed to receive
Get tree menu list
云计算之路-出海记:整一台 aws 免费云服务器
c# 表达式树(一)
QT hybrid Python development technology: Python introduction, hybrid process and demo
来自不同行业领域的50多个对象检测数据集
C expression tree (1)
These core technology of object-oriented, after you master it, you can have a good interview
The emergence and significance of micro service
Face recognition: attack types and anti spoofing techniques
C++在C的基础上改进了哪些细节
leetcode之判断路径是否相交
Jingtao project day09
Qt混合Python开发技术:Python介绍、混合过程和Demo