当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- easyui dialog“缓存问题”
- Download, installation and configuration of Sogou input method in Ubuntu
- Qt混合Python开发技术:Python介绍、混合过程和Demo
- 面部识别:攻击类型和反欺骗技术
- Wanxin Finance
- These core technology of object-oriented, after you master it, you can have a good interview
- See once to understand, graphic single chain table inversion
- 你可能不知道的Animation动画技巧与细节
- Do you really understand the high concurrency?
- supervisor和Python多进程multiprocessing使用 子进程残留问题
猜你喜欢
爆一个VS2015 Update1更新带来的编译BUG【已有解决方案】
Jingtao project day09
Wechat applet request reported 400 error @ requestbody failed to receive
Download, installation and configuration of Sogou input method in Ubuntu
Goland 编写含有template的程序
C language I blog assignment 03
leetcode之判断路径是否相交
Ubuntu下搜狗输入法的下载安装及配置
0.计算机简史
Learn Scala if Else statement
随机推荐
Ladongo open source full platform penetration scanner framework
leetcode之判断路径是否相交
Delphi10's rest.json And system.json Step on the pit
UCGUI简介
C语言I博客作业03
QT hybrid Python development technology: Python introduction, hybrid process and demo
1.深入Istio:Sidecar自动注入如何实现的?
数据库基本操作
Got timeout reading communication packets解决方法
Android 9.0/P WebView 多进程使用的问题
Android Basics - RadioButton (radio button)
Abnormal + Abstract
14000 word distributed transaction principle analysis, master all of them, are you afraid of being asked in the interview?
Web安全(三)---CSRF攻击
Go sending pin and email
ubuntu实时显示cpu、内存占用率
学习Scala IF…ELSE 语句
爆一个VS2015 Update1更新带来的编译BUG【已有解决方案】
Ubuntu下搜狗输入法的下载安装及配置
一万四千字分布式事务原理解析,全部掌握你还怕面试被问?