当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 工作1-3年的程序员,应该具备怎么样的技术能力?该如何提升?
- On the concurrency of update operation
- android基础-RadioButton(单选按钮)
- More than 50 object detection datasets from different industries
- Got timeout reading communication packets解决方法
- Judging whether paths intersect or not by leetcode
- Speed up your website with jsdelivr
- 看一遍就理解,图解单链表反转
- LadonGo开源全平台渗透扫描器框架
- 爆一个VS2015 Update1更新带来的编译BUG【已有解决方案】
猜你喜欢
随机推荐
CPP (1) installation of cmake
ngnix集群高并发
High concurrency in ngnix cluster
ROS learning: remote start ROS node
supervisor和Python多进程multiprocessing使用 子进程残留问题
C/C++编程笔记:C语言相比其他编程语言,有什么不一样的优势?
C++基础知识篇:C++ 基本语法
1. In depth istio: how is sidecar auto injection realized?
WPF personal summary on drawing
关于update操作并发问题
Thinkphp6中where条件中字段与字段比较条件的写法
云计算之路-出海记:整一台 aws 免费云服务器
Got timeout reading communication packets解决方法
Web安全(二)---跨域资源共享
Judging whether paths intersect or not by leetcode
What kind of technical ability should a programmer who has worked for 1-3 years? How to improve?
计组-总线通信控制之异步串行通信的数据传输
Sentry 安装
Cpp(三) 什么是CMake
虚拟DOM中给同一层级的元素设置固定且唯一的key为什么能提高性能






