当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 获取树形菜单列表
- Wechat applet request reported 400 error @ requestbody failed to receive
- 面部识别:攻击类型和反欺骗技术
- Android 9.0/P WebView 多进程使用的问题
- Jingtao project day09
- WPF personal summary on drawing
- 微信小程序request报400错误 @RequestBody接收不到
- China Telecom announces 5g SA commercial scale in 2020
- 面部识别:攻击类型和反欺骗技术
- More than 50 object detection datasets from different industries
猜你喜欢

微信昵称emoji表情,特殊表情导致列表不显示,导出EXCEL报错等问题解决!

delphi10的rest.json与system.json的踩坑

使用 Xunit.DependencyInjection 改造测试项目

Qt混合Python开发技术:Python介绍、混合过程和Demo

关于晋升全栈工程师,从入门到放弃的神功秘籍,不点进来看一看?

Privacy violation and null dereference of fortify vulnerability

Android 9.0/P WebView 多进程使用的问题

The real-time display of CPU and memory utilization rate by Ubuntu

【解决方案】分布式定时任务解决方案

2020天翼智能生态博览会中国电信宣布5G SA正式规模商用
随机推荐
Fortify漏洞之 Privacy Violation(隐私泄露)和 Null Dereference(空指针异常)
Judging whether paths intersect or not by leetcode
What details does C + + improve on the basis of C
C++基础知识篇:C++ 基本语法
Qt混合Python开发技术:Python介绍、混合过程和Demo
C / C + + Programming Notes: what are the advantages of C compared with other programming languages?
云计算之路-出海记:整一台 aws 免费云服务器
C language I blog assignment 03
团灭 LeetCode 股票买卖问题
Android Basics - RadioButton (radio button)
Sentry installation
GET,POST,PUT,DELETE,OPTIONS用法与说明
接口
面部识别:攻击类型和反欺骗技术
CPP (1) installation of cmake
【解决方案】分布式定时任务解决方案
什么你的电脑太渣?这几招包你搞定! (Win10优化教程)
什么都2020了,LINQ查询你还在用表达式树
Wechat applet request reported 400 error @ requestbody failed to receive
Learn Scala if Else statement