当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
猜你喜欢
看一遍就理解,图解单链表反转
Problems of Android 9.0/p WebView multi process usage
Learn Scala if Else statement
云计算之路-出海记:整一台 aws 免费云服务器
China Telecom announces 5g SA commercial scale in 2020
C语言I博客作业03
14000 word distributed transaction principle analysis, master all of them, are you afraid of being asked in the interview?
【解决方案】分布式定时任务解决方案
高并发,你真的理解透彻了吗?
Privacy violation and null dereference of fortify vulnerability
随机推荐
京淘项目知识点总结
面部识别:攻击类型和反欺骗技术
awk实现类sql的join操作
WPF 关于绘图个人总结
一万四千字分布式事务原理解析,全部掌握你还怕面试被问?
Judging whether paths intersect or not by leetcode
尾-递
Lay UI left tree Dtree right list table
QT hybrid Python development technology: Python introduction, hybrid process and demo
CPP (1) installation of cmake
Fortify漏洞之 Privacy Violation(隐私泄露)和 Null Dereference(空指针异常)
ROS learning: remote start ROS node
Improvement of maintenance mode of laravel8 update
16.文件传输协议、vsftpd服务
supervisor进程管理安装使用
关于update操作并发问题
CPP (2) creating CPP project
Cpp(二) 创建Cpp工程
团灭 LeetCode 股票买卖问题
Go之发送钉钉和邮箱