kotlin协程_Kotlin协程

kotlin协程

In this tutorial, we’ll be looking into Kotlin Coroutines. Coroutines is a vital concept since asynchronous programming is the way to go over the traditional blocking a thread and polling stuff.

在本教程中,我们将研究Kotlin协程。 协程是一个至关重要的概念,因为异步编程是克服传统的阻塞线程和轮询内容的方法。

Kotlin协程 (Kotlin Coroutines)

Concurrency is vital in programming. Running different tasks on different threads. But sometimes, we as developers can get carried away and create too many Thread objects which would eventually consume a lot of memory and time. Thankfully, Kotlin has introduced Coroutines which are light-weight threads.

并发在编程中至关重要。 在不同的线程上运行不同的任务。 但是有时候,作为开发人员,我们会被带走,创建太多的Thread对象,这些对象最终会占用大量内存和时间。 值得庆幸的是,Kotlin推出了轻量级的协程。

By light-weight threads we mean, Coroutines take less memory and time compared with the default Java threads.
Coroutines though currently in the initial stages only, has a powerful set of libraries which we can use to make the computation stuff easy.

轻量级线程是我们的意思,与默认的Java线程相比,协程占用的内存和时间更少。
虽然协程目前仅处于初始阶段,但它具有一组功能强大的库,我们可以使用它们简化计算工作。

Coroutines computations can be done without blocking other threads.

协程计算可以在不阻塞其他线程的情况下完成。

How?

怎么样?

Suspending Functions is the answer to it.

暂停功能是解决之道。

Suspending functions are introduced with Coroutines and allow us to start the function from where it left off. This aids further in memory optimizations of the CPU and multi-tasking.
协程(Coroutines)引入了暂停功能,使我们可以从中断处开始启动该功能。 这进一步有助于CPU的内存优化和多任务处理。

Unlike blocking a thread, suspending functions are less expensive and do not require a context switching.

与阻塞线程不同,挂起函数的开销较小,并且不需要上下文切换。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值