当前位置:网站首页>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
边栏推荐
- wanxin金融
- On the concurrency of update operation
- 汇编函数mcall systemstack asmcgocall syscall
- C++基础知识篇:C++ 基本语法
- Web Security (3) -- CSRF attack
- Tail delivery
- The software in your host has terminated an established connection. resolvent
- leetcode之判断路径是否相交
- Adobe Prelude / PL 2020 software installation package (with installation tutorial)
- Do you really understand the high concurrency?
猜你喜欢

高并发,你真的理解透彻了吗?

QT hybrid Python development technology: Python introduction, hybrid process and demo

IDEA-项目未自动生成 .iml 文件

C / C + + Programming Notes: what are the advantages of C compared with other programming languages?

Improvement of maintenance mode of laravel8 update

C language I blog assignment 03

Experience the latest version of erofs on Ubuntu

工作1-3年的程序员,应该具备怎么样的技术能力?该如何提升?

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

Data structure and sorting algorithm
随机推荐
Adobe media encoder / me 2021 software installation package (with installation tutorial)
微服务的出现和意义的探索
Go之发送钉钉和邮箱
Go sending pin and email
微信昵称emoji表情,特殊表情导致列表不显示,导出EXCEL报错等问题解决!
supervisor和Python多进程multiprocessing使用 子进程残留问题
November 07, 2020: given an array of positive integers, the sum of two numbers equals N and must exist. How to find the two numbers with the smallest multiplication?
C language I blog assignment 03
【解决方案】分布式定时任务解决方案
Web Security (3) -- CSRF attack
Adobe Lightroom / LR 2021 software installation package (with installation tutorial)
16.文件传输协议、vsftpd服务
Speed up your website with jsdelivr
异常+abstract
See once to understand, graphic single chain table inversion
QT hybrid Python development technology: Python introduction, hybrid process and demo
Jingtao project day09
Cpp(四) Boost安装及基本使用 for Mac
CPP (3) what is cmake
LadonGo开源全平台渗透扫描器框架