83
83
Error: Kotlin: Suspend functions are only allowed to be called from a coroutine or another suspend function
84
84
```
85
85
86
- 这是因为 [ delay] 是一个特别的 _ 暂停函数 _ , 它不会造成线程阻塞,但是 _ 暂停 _ <!--
86
+ 这是因为 [ delay] 是一个特别的 _ 挂起函数 _ , 它不会造成线程阻塞,但是 _ 挂起 _ <!--
87
87
-->函数只能在协程中使用.
88
88
89
89
### 桥接阻塞和非阻塞的世界
@@ -151,7 +151,7 @@ World!
151
151
这里的 ` runBlocking<Unit> { ... } ` 作为一个适配器被用来启动最高优先级的主协程。
152
152
我们明确的声明 ` Unit ` 为返回值类型,因为Kotlin中的` main ` 函数返回` Unit ` 类型。
153
153
154
- 这也是一种使用暂停函数来实现单元测试的方法 :
154
+ 这也是一种使用挂起函数来实现单元测试的方法 :
155
155
156
156
<!-- - INCLUDE
157
157
import kotlinx.coroutines.*
@@ -163,7 +163,7 @@ import kotlinx.coroutines.*
163
163
class MyTest {
164
164
@Test
165
165
fun testMySuspendingFunction () = runBlocking<Unit > {
166
- // 这里我们可以使用暂停函数来实现任何我们喜欢的断言风格
166
+ // 这里我们可以使用挂起函数来实现任何我们喜欢的断言风格
167
167
}
168
168
}
169
169
```
@@ -294,8 +294,8 @@ Coroutine scope is over
294
294
295
295
让我们在 ` launch { ... } ` 中提取代码块并分离到另一个函数中. 当你
296
296
在这段代码上展示"提取函数"函数的时候, 你的到了一个新的函数并用 ` suspend ` 修饰.
297
- 这是你的第一个 _ 暂停函数 _ 。暂停函数可以像一个普通的函数一样使用内部协程 ,但是它们拥有一些额外的特性,反过来说,
298
- 使用其它的暂停函数 , 比如这个例子中的 ` delay ` ,可以使协程暂停执行。
297
+ 这是你的第一个 _ 挂起函数 _ 。挂起函数可以像一个普通的函数一样使用内部协程 ,但是它们拥有一些额外的特性,反过来说,
298
+ 使用其它的挂起函数 , 比如这个例子中的 ` delay ` ,可以使协程暂停执行。
299
299
300
300
<div class =" sample " markdown =" 1 " theme =" idea " data-min-compiler-version =" 1.3 " >
301
301
@@ -307,7 +307,7 @@ fun main() = runBlocking {
307
307
println (" Hello," )
308
308
}
309
309
310
- // 你的第一个暂停函数
310
+ // 你的第一个挂起函数
311
311
suspend fun doWorld () {
312
312
delay(1000L )
313
313
println (" World!" )
0 commit comments