当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 14000 word distributed transaction principle analysis, master all of them, are you afraid of being asked in the interview?
- 学习Scala IF…ELSE 语句
- Golang anonymous structure member, named structure member, inheritance, composition
- Abnormal + Abstract
- 云计算之路-出海记:整一台 aws 免费云服务器
- CPP (4) boost installation and basic use for Mac
- golang 匿名结构体成员,具名结构体成员,继承,组合
- Adobe Prelude / PL 2020 software installation package (with installation tutorial)
- 16. File transfer protocol, vsftpd service
- 什么都2020了,LINQ查询你还在用表达式树
猜你喜欢
Goland 编写含有template的程序
Everything is 2020, LINQ query you are still using expression tree
微信昵称emoji表情,特殊表情导致列表不显示,导出EXCEL报错等问题解决!
16.文件传输协议、vsftpd服务
在Ubuntu上体验最新版本EROFS
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?
The real-time display of CPU and memory utilization rate by Ubuntu
On the stock trading of leetcode
1.深入Istio:Sidecar自动注入如何实现的?
团灭 LeetCode 股票买卖问题
随机推荐
什么你的电脑太渣?这几招包你搞定! (Win10优化教程)
工作1-3年的程序员,应该具备怎么样的技术能力?该如何提升?
2020天翼智能生态博览会中国电信宣布5G SA正式规模商用
Adobe media encoder / me 2021 software installation package (with installation tutorial)
Data structure and sorting algorithm
Android 9.0/P WebView 多进程使用的问题
WPF personal summary on drawing
awk实现类sql的join操作
Get tree menu list
Getting started with go wire dependency injection
Go之发送钉钉和邮箱
C++在C的基础上改进了哪些细节
C/C++编程笔记:C语言相比其他编程语言,有什么不一样的优势?
LadonGo开源全平台渗透扫描器框架
Golang anonymous structure member, named structure member, inheritance, composition
16. File transfer protocol, vsftpd service
ubuntu实时显示cpu、内存占用率
Cpp(一) 安装CMake
A compilation bug brought by vs2015 Update1 update [existing solutions]
什么都2020了,LINQ查询你还在用表达式树