当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Hand tearing algorithm - handwritten singleton mode
- Go sending pin and email
- 你可能不知道的Animation动画技巧与细节
- supervisor和Python多进程multiprocessing使用 子进程残留问题
- 虚拟DOM中给同一层级的元素设置固定且唯一的key为什么能提高性能
- Qt混合Python开发技术:Python介绍、混合过程和Demo
- Wechat applet request reported 400 error @ requestbody failed to receive
- 面部识别:攻击类型和反欺骗技术
- ROS学习---远程启动ROS节点
- What kind of technical ability should a programmer who has worked for 1-3 years? How to improve?
猜你喜欢
Introduction to ucgui
Get tree menu list
See once to understand, graphic single chain table inversion
一万四千字分布式事务原理解析,全部掌握你还怕面试被问?
Basic operation of database
Go之发送钉钉和邮箱
A compilation bug brought by vs2015 Update1 update [existing solutions]
On the stock trading of leetcode
面部识别:攻击类型和反欺骗技术
Experience the latest version of erofs on Ubuntu
随机推荐
C / C + + Programming Notes: what are the advantages of C compared with other programming languages?
Judging whether paths intersect or not by leetcode
高并发,你真的理解透彻了吗?
Web Security (3) -- CSRF attack
Using subprocess residue in supervisor and python multiprocessing
A compilation bug brought by vs2015 Update1 update [existing solutions]
什么都2020了,LINQ查询你还在用表达式树
Lay UI left tree Dtree right list table
鼠标变小手
手撕算法-手写单例模式
2020天翼智能生态博览会中国电信宣布5G SA正式规模商用
Goland 编写含有template的程序
China Telecom announces 5g SA commercial scale in 2020
到底选openstack还是vmware?
Download, installation and configuration of Sogou input method in Ubuntu
16.文件传输协议、vsftpd服务
c# 表达式树(一)
ROS学习---远程启动ROS节点
QT hybrid Python development technology: Python introduction, hybrid process and demo
学习Scala IF…ELSE 语句