当前位置:网站首页>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
边栏推荐
- ubuntu实时显示cpu、内存占用率
- Getting started with go wire dependency injection
- CPP (1) installation of cmake
- Problems of Android 9.0/p WebView multi process usage
- 获取树形菜单列表
- VC6兼容性及打开文件崩溃问题解决
- Lay UI left tree Dtree right list table
- GoLand writes a program with template
- 你可能不知道的Animation动画技巧与细节
- Do you really understand the high concurrency?
猜你喜欢
密码学-尚硅谷
Cryptography - Shangsi Valley
C++基础知识篇:C++ 基本语法
什么都2020了,LINQ查询你还在用表达式树
QT hybrid Python development technology: Python introduction, hybrid process and demo
China Telecom announces 5g SA commercial scale in 2020
Introduction to ucgui
工作1-3年的程序员,应该具备怎么样的技术能力?该如何提升?
Face recognition: attack types and anti spoofing techniques
Idea - the. IML file was not automatically generated by the project
随机推荐
Problems of Android 9.0/p WebView multi process usage
获取树形菜单列表
Supervisor process management installation and use
easyui dialog“缓存问题”
微服务的出现和意义的探索
laravel8更新之维护模式改进
Download, installation and configuration of Sogou input method in Ubuntu
面部识别:攻击类型和反欺骗技术
Adobe Lightroom /Lr 2021软件安装包(附安装教程)
Insight -- the application of sanet in arbitrary style transfer
C/C++编程笔记:C语言相比其他编程语言,有什么不一样的优势?
golang 匿名结构体成员,具名结构体成员,继承,组合
16.文件传输协议、vsftpd服务
【解决方案】分布式定时任务解决方案
Judging whether paths intersect or not by leetcode
关于update操作并发问题
Adobe Lightroom / LR 2021 software installation package (with installation tutorial)
delphi10的rest.json与system.json的踩坑
Search and replace of sed
Goland 编写含有template的程序