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

More than 50 object detection datasets from different industries

2020天翼智能生态博览会中国电信宣布5G SA正式规模商用

These core technology of object-oriented, after you master it, you can have a good interview

团灭 LeetCode 股票买卖问题

use Xunit.DependencyInjection Transformation test project

Problems of Android 9.0/p WebView multi process usage

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

Privacy violation and null dereference of fortify vulnerability

面部识别:攻击类型和反欺骗技术

VC6 compatibility and open file crash resolution
随机推荐
QT hybrid Python development technology: Python introduction, hybrid process and demo
The real-time display of CPU and memory utilization rate by Ubuntu
Web安全(四)---XSS攻击
Wechat applet request reported 400 error @ requestbody failed to receive
状态压缩:对动态规划进行降维打击
VC6兼容性及打开文件崩溃问题解决
ROS学习---远程启动ROS节点
Android Basics - RadioButton (radio button)
supervisor进程管理安装使用
一万四千字分布式事务原理解析,全部掌握你还怕面试被问?
Web安全(二)---跨域资源共享
Delphi10's rest.json And system.json Step on the pit
Basic operation of database
密码学-尚硅谷
GET,POST,PUT,DELETE,OPTIONS用法与说明
China Telecom announces 5g SA commercial scale in 2020
京淘项目day09
你的主机中的软件中止了一个已建立的连接。解决方法
C语言I博客作业03
PerconaXtraDBCluster8.0 最详尽用法指南