当前位置:网站首页>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
边栏推荐
- China Telecom announces 5g SA commercial scale in 2020
- Data transmission of asynchronous serial communication controlled by group bus communication
- Wanxin Finance
- Web安全(三)---CSRF攻击
- 来自不同行业领域的50多个对象检测数据集
- CPP (4) boost installation and basic use for Mac
- Assembly function MCALL systemstack asmcgocal system call
- Sentry 安装
- C++基础知识篇:C++ 基本语法
- 虚拟DOM中给同一层级的元素设置固定且唯一的key为什么能提高性能
猜你喜欢

laravel8更新之维护模式改进

VC6 compatibility and open file crash resolution

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?

WPF 关于绘图个人总结

微服务的出现和意义的探索

c# 表达式树(一)

看一遍就理解,图解单链表反转

状态压缩:对动态规划进行降维打击

ubuntu实时显示cpu、内存占用率

LadonGo开源全平台渗透扫描器框架
随机推荐
Cpp(三) 什么是CMake
获取树形菜单列表
微服务的出现和意义的探索
汇编函数mcall systemstack asmcgocall syscall
CPP (1) installation of cmake
Learn Scala if Else statement
QT hybrid Python development technology: Python introduction, hybrid process and demo
看一遍就理解,图解单链表反转
微信昵称emoji表情,特殊表情导致列表不显示,导出EXCEL报错等问题解决!
Basic knowledge of C + +
Wechat applet request reported 400 error @ requestbody failed to receive
Qt混合Python开发技术:Python介绍、混合过程和Demo
sed之查找替换
京淘项目day09
Privacy violation and null dereference of fortify vulnerability
Sentry 安装
数据库基本操作
More than 50 object detection datasets from different industries
About the promotion of the whole stack of engineers, from the introduction to give up the secret arts, do not click in to have a look?
Python 图片识别 OCR