当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 鼠标变小手
- Python image recognition OCR
- UCGUI简介
- supervisor进程管理安装使用
- Download, installation and configuration of Sogou input method in Ubuntu
- Get tree menu list
- 16. File transfer protocol, vsftpd service
- Face recognition: attack types and anti spoofing techniques
- Introduction to ucgui
- Summary of knowledge points of Jingtao project
猜你喜欢
Brief history of computer
0.计算机简史
Ladongo open source full platform penetration scanner framework
QT hybrid Python development technology: Python introduction, hybrid process and demo
2020天翼智能生态博览会中国电信宣布5G SA正式规模商用
密码学-尚硅谷
C language I blog assignment 03
Mouse small hand
Learn Scala if Else statement
微服务的出现和意义的探索
随机推荐
Face recognition: attack types and anti spoofing techniques
Cpp(三) 什么是CMake
获取树形菜单列表
Search and replace of sed
On the concurrency of update operation
Web Security (4) -- XSS attack
High concurrency in ngnix cluster
WPF personal summary on drawing
Cryptography - Shangsi Valley
Android 9.0/P WebView 多进程使用的问题
Insight -- the application of sanet in arbitrary style transfer
数据库基本操作
delphi10的rest.json与system.json的踩坑
虚拟DOM中给同一层级的元素设置固定且唯一的key为什么能提高性能
Web安全(三)---CSRF攻击
尾-递
你可能不知道的Animation动画技巧与细节
手撕算法-手写单例模式
Basic operation of database
ROS学习---远程启动ROS节点