当前位置:网站首页>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
边栏推荐
- Mouse small hand
- supervisor进程管理安装使用
- QT hybrid Python development technology: Python introduction, hybrid process and demo
- ROS learning: remote start ROS node
- More than 50 object detection datasets from different industries
- GET,POST,PUT,DELETE,OPTIONS用法与说明
- Judging whether paths intersect or not by leetcode
- Search and replace of sed
- Thinkphp6中where条件中字段与字段比较条件的写法
- On the concurrency of update operation
猜你喜欢

C++基础知识篇:C++ 基本语法

Wanxin Finance

More than 50 object detection datasets from different industries

QT hybrid Python development technology: Python introduction, hybrid process and demo

More than 50 object detection datasets from different industries

微信昵称emoji表情,特殊表情导致列表不显示,导出EXCEL报错等问题解决!

Delphi10's rest.json And system.json Step on the pit

Get tree menu list
![A compilation bug brought by vs2015 Update1 update [existing solutions]](/img/3b/00bc81122d330c9d59909994e61027.jpg)
A compilation bug brought by vs2015 Update1 update [existing solutions]

android基础-RadioButton(单选按钮)
随机推荐
High concurrency in ngnix cluster
关于update操作并发问题
Adobe Prelude /Pl 2020软件安装包(附安装教程)
Go sending pin and email
Adobe Prelude / PL 2020 software installation package (with installation tutorial)
在Ubuntu上体验最新版本EROFS
Judging whether paths intersect or not by leetcode
Web Security (1) -- browser homology strategy
c# 表达式树(一)
Qt混合Python开发技术:Python介绍、混合过程和Demo
The real-time display of CPU and memory utilization rate by Ubuntu
Supervisor process management installation and use
Using subprocess residue in supervisor and python multiprocessing
汇编函数mcall systemstack asmcgocall syscall
Search and replace of sed
WPF 关于绘图个人总结
一万四千字分布式事务原理解析,全部掌握你还怕面试被问?
微信昵称emoji表情,特殊表情导致列表不显示,导出EXCEL报错等问题解决!
ngnix集群高并发
Idea - the. IML file was not automatically generated by the project