当前位置:网站首页>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
边栏推荐
- Python 图片识别 OCR
- 汇编函数mcall systemstack asmcgocall syscall
- Writing method of field and field comparison condition in where condition in thinkphpp6
- 1. In depth istio: how is sidecar auto injection realized?
- Awk implements SQL like join operation
- 虚拟DOM中给同一层级的元素设置固定且唯一的key为什么能提高性能
- awk实现类sql的join操作
- Adobe Lightroom /Lr 2021软件安装包(附安装教程)
- Download, installation and configuration of Sogou input method in Ubuntu
- 2020天翼智能生态博览会中国电信宣布5G SA正式规模商用
猜你喜欢
爆一个VS2015 Update1更新带来的编译BUG【已有解决方案】
16.文件传输协议、vsftpd服务
QT hybrid Python development technology: Python introduction, hybrid process and demo
看一遍就理解,图解单链表反转
获取树形菜单列表
A compilation bug brought by vs2015 Update1 update [existing solutions]
Cryptography - Shangsi Valley
Do you really understand the high concurrency?
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?
More than 50 object detection datasets from different industries
随机推荐
Sentry installation
高并发,你真的理解透彻了吗?
Web安全(四)---XSS攻击
京淘项目day09
微信小程序request报400错误 @RequestBody接收不到
Brief history of computer
Wechat applet request reported 400 error @ requestbody failed to receive
来自不同行业领域的50多个对象检测数据集
Get tree menu list
Python 图片识别 OCR
2020天翼智能生态博览会中国电信宣布5G SA正式规模商用
Wanxin Finance
Mouse small hand
Adobe Lightroom /Lr 2021软件安装包(附安装教程)
CPP (1) installation of cmake
Getting started with go wire dependency injection
Thinkphp6中where条件中字段与字段比较条件的写法
Go sending pin and email
VC6 compatibility and open file crash resolution
鼠标变小手