当前位置:网站首页>scala 中 Future 的简单使用
scala 中 Future 的简单使用
2020-11-07 23:58:00 【lemos】
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)
}
// 通过视界转换,让 Int 拥有更丰富的方法
// 由于继承了 AnyVal,表明这是一个 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)
}
}
版权声明
本文为[lemos]所创,转载请带上原文链接,感谢
https://my.oschina.net/lemos/blog/4707772
边栏推荐
- Adobe Prelude / PL 2020 software installation package (with installation tutorial)
- 在Ubuntu上体验最新版本EROFS
- VC6兼容性及打开文件崩溃问题解决
- Data structure and sorting algorithm
- GET,POST,PUT,DELETE,OPTIONS用法与说明
- Data transmission of asynchronous serial communication controlled by group bus communication
- What details does C + + improve on the basis of C
- 1.深入Istio:Sidecar自动注入如何实现的?
- UCGUI简介
- Cpp(四) Boost安装及基本使用 for Mac
猜你喜欢
These core technology of object-oriented, after you master it, you can have a good interview
Animation techniques and details you may not know
一万四千字分布式事务原理解析,全部掌握你还怕面试被问?
Basic knowledge of C + +
14000 word distributed transaction principle analysis, master all of them, are you afraid of being asked in the interview?
QT hybrid Python development technology: Python introduction, hybrid process and demo
Qt混合Python开发技术:Python介绍、混合过程和Demo
wanxin金融
Get tree menu list
The road of cloud computing: a free AWS cloud server
随机推荐
构造请求日志分析系统
使用jsDelivr加速你的网站
Wanxin Finance
Android 9.0/P WebView 多进程使用的问题
尾-递
ngnix集群高并发
supervisor进程管理安装使用
Using subprocess residue in supervisor and python multiprocessing
GET,POST,PUT,DELETE,OPTIONS用法与说明
Summary of knowledge points of Jingtao project
Everything is 2020, LINQ query you are still using expression tree
C/C++编程笔记:C语言相比其他编程语言,有什么不一样的优势?
Web Security (4) -- XSS attack
CPP (4) boost installation and basic use for Mac
Web安全(一)---浏览器同源策略
laravel8更新之维护模式改进
android基础-RadioButton(单选按钮)
面部识别:攻击类型和反欺骗技术
Privacy violation and null dereference of fortify vulnerability
Improvement of maintenance mode of laravel8 update