Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
# Conflicts (resolved):
#	docs/basics.md
#	docs/cancellation-and-timeouts.md
#	docs/channels.md
#	docs/composing-suspending-functions.md
#	docs/coroutine-context-and-dispatchers.md
#	docs/coroutines-guide.md
#	docs/exception-handling.md
#	docs/select-expression.md
#	docs/shared-mutable-state-and-concurrency.md
#	reactive/coroutines-guide-reactive.md
#	ui/coroutines-guide-ui.md
  • Loading branch information
hltj committed Apr 22, 2019
2 parents 1b93062 + 69c26df commit e7cd628
Show file tree
Hide file tree
Showing 53 changed files with 209 additions and 208 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Visible consequences of include more robust exception handling for large corouti
* Distribution no longer uses multi-version jar which is not supported on Android (see #510).
* JS version of the library does not depend on AtomicFu anymore:
  All the atomic boxes in JS are fully erased.
* Note, that versions 0.25.1-2 are skipped for technical reasons (they were not fully released).
* Note that versions 0.25.1-2 are skipped for technical reasons (they were not fully released).

## Version 0.25.0

Expand Down
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ To release new `<version>` of `kotlinx-coroutines`:
* Run "Deploy (Configure, RUN THIS ONE)" configuration with the corresponding new version.

2. In [GitHub](https://github.com/kotlin/kotlinx.coroutines) interface:
* Create new release named as `<version>`.
* Create a release named `<version>`.
* Cut & paste lines from [`CHANGES.md`](CHANGES.md) into description.

3. Build and publish documentation for web-site: <br>
Expand Down
24 changes: 12 additions & 12 deletions docs/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fun main() {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-01.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-01.kt)获取完整代码。
代码运行的结果:

Expand Down Expand Up @@ -111,7 +111,7 @@ fun main() {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-02.kt)来获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-02.kt)获取完整代码。
<!--- TEST
Hello,
Expand Down Expand Up @@ -141,7 +141,7 @@ fun main() = runBlocking<Unit> { // 开始执行主协程

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-02b.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-02b.kt)获取完整代码。
<!--- TEST
Hello,
Expand Down Expand Up @@ -196,7 +196,7 @@ fun main() = runBlocking {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-03.kt)来获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-03.kt)获取完整代码。
<!--- TEST
Hello,
Expand Down Expand Up @@ -231,7 +231,7 @@ World!
import kotlinx.coroutines.*

fun main() = runBlocking { // this: CoroutineScope
launch { // 在 runBlocking 作用域中启动新协程
launch { // 在 runBlocking 作用域中启动一个新协程
delay(1000L)
println("World!")
}
Expand All @@ -241,7 +241,7 @@ fun main() = runBlocking { // this: CoroutineScope

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-03s.kt)来获取完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-03s.kt)获取完整代码。
<!--- TEST
Hello,
Expand All @@ -250,7 +250,7 @@ World!

### 作用域构建器
除了由不同的构建器提供协程作用域之外,还可以使用
[coroutineScope] 构建器声明自己的作用域。它会创建新的协程作用域并且在所有已启动子协程执行完毕之前不会<!--
[coroutineScope] 构建器声明自己的作用域。它会创建一个协程作用域并且在所有已启动子协程执行完毕之前不会<!--
-->结束。[runBlocking][coroutineScope] 的主要区别在于后者<!--
-->在等待所有子协程执行完毕时不会阻塞当前线程。

Expand All @@ -265,7 +265,7 @@ fun main() = runBlocking { // this: CoroutineScope
println("Task from runBlocking")
}

coroutineScope { // 创建一个新的协程作用域
coroutineScope { // 创建一个协程作用域
launch {
delay(500L)
println("Task from nested launch")
Expand All @@ -281,7 +281,7 @@ fun main() = runBlocking { // this: CoroutineScope

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-04.kt)来获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-04.kt)获取完整代码。
<!--- TEST
Task from coroutine scope
Expand Down Expand Up @@ -317,7 +317,7 @@ suspend fun doWorld() {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-05.kt)来获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-05.kt)获取完整代码。
<!--- TEST
Hello,
Expand Down Expand Up @@ -354,7 +354,7 @@ fun main() = runBlocking {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-06.kt)来获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-06.kt)获取完整代码。
<!--- TEST lines.size == 1 && lines[0] == ".".repeat(100_000) -->

Expand Down Expand Up @@ -386,7 +386,7 @@ fun main() = runBlocking {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-07.kt)来获取完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-basic-07.kt)获取完整代码。
你可以运行这个程序并看到它输出了以下三行后终止:

Expand Down
14 changes: 7 additions & 7 deletions docs/cancellation-and-timeouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fun main() = runBlocking {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-01.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-01.kt)获取完整代码。
程序执行后的输出如下:

Expand Down Expand Up @@ -119,7 +119,7 @@ fun main() = runBlocking {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-02.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-02.kt)获取完整代码。
运行示例代码,并且我们可以看到它连续打印出了“I'm sleeping” ,甚至在调用取消后,
任务仍然执行了五次循环迭代并运行到了它结束为止。
Expand Down Expand Up @@ -171,7 +171,7 @@ fun main() = runBlocking {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-03.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-03.kt)获取完整代码。
你可以看到,现在循环被取消了。[isActive] 是一个可以被使用在
[CoroutineScope] 中的扩展属性。
Expand Down Expand Up @@ -218,7 +218,7 @@ fun main() = runBlocking {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-04.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-04.kt)获取完整代码。
[join][Job.join][cancelAndJoin] 等待了所有的终结动作执行完毕,
所以运行示例得到了下面的输出:
Expand Down Expand Up @@ -274,7 +274,7 @@ fun main() = runBlocking {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-05.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-05.kt)获取完整代码。
<!--- TEST
I'm sleeping 0 ...
Expand Down Expand Up @@ -313,7 +313,7 @@ fun main() = runBlocking {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-06.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-06.kt)获取完整代码。
运行后得到如下输出:

Expand Down Expand Up @@ -357,7 +357,7 @@ fun main() = runBlocking {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-07.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-07.kt)获取完整代码。
运行这段代码时不再抛出异常:

Expand Down
20 changes: 10 additions & 10 deletions docs/channels.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fun main() = runBlocking {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-01.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-01.kt)获取完整代码。
这段代码的输出如下:

Expand Down Expand Up @@ -119,7 +119,7 @@ fun main() = runBlocking {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-02.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-02.kt)获取完整代码。
<!--- TEST
1
Expand Down Expand Up @@ -161,7 +161,7 @@ fun main() = runBlocking {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-03.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-03.kt)获取完整代码。
<!--- TEST
1
Expand Down Expand Up @@ -232,7 +232,7 @@ fun CoroutineScope.square(numbers: ReceiveChannel<Int>): ReceiveChannel<Int> = p

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-04.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-04.kt)获取完整代码。
<!--- TEST
1
Expand Down Expand Up @@ -323,7 +323,7 @@ fun CoroutineScope.filter(numbers: ReceiveChannel<Int>, prime: Int) = produce<In

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-05.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-05.kt)获取完整代码。
这段代码的输出如下:

Expand Down Expand Up @@ -426,7 +426,7 @@ fun CoroutineScope.launchProcessor(id: Int, channel: ReceiveChannel<Int>) = laun

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-06.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-06.kt)获取完整代码。
该输出将类似于如下所示,尽管接收的是生产者的 id
但每个整数也许会不同:
Expand Down Expand Up @@ -506,7 +506,7 @@ suspend fun sendString(channel: SendChannel<String>, s: String, time: Long) {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-07.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-07.kt)获取完整代码。
输出如下:

Expand Down Expand Up @@ -558,7 +558,7 @@ fun main() = runBlocking<Unit> {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-08.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-08.kt)获取完整代码。
使用缓冲通道并给 capacity 参数传入 __ 它将打印“sending” __ 次:

Expand Down Expand Up @@ -613,7 +613,7 @@ suspend fun player(name: String, table: Channel<Ball>) {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-09.kt)得到完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-09.kt)得到完整代码
“乒”协程首先被启动,所以它首先接收到了球。甚至虽然“乒”
协程在将球发送会桌子以后立即开始接收,但是球还是被“乓”
Expand Down Expand Up @@ -676,7 +676,7 @@ fun main() = runBlocking<Unit> {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-10.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-channel-10.kt)获取完整代码。
它的打印如下:

Expand Down
22 changes: 11 additions & 11 deletions docs/composing-suspending-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ suspend fun doSomethingUsefulTwo(): Int {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-compose-01.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-compose-01.kt)获取完整代码。
它的打印输出如下:

Expand Down Expand Up @@ -150,7 +150,7 @@ suspend fun doSomethingUsefulTwo(): Int {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-compose-02.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-compose-02.kt)获取完整代码。
它的打印输出如下:

Expand Down Expand Up @@ -204,7 +204,7 @@ suspend fun doSomethingUsefulTwo(): Int {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-compose-03.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-compose-03.kt)获取完整代码。
它的打印输出如下:

Expand All @@ -219,11 +219,11 @@ Completed in 1017 ms
-->程序员准确的在开始执行时调用 [start][Job.start]。我们首先
调用 `one`,然后调用 `two`,接下来等待这个协程执行完毕。

注意,如果我们在 `println` 中调用了 [await][Deferred.await] 并且在这个协程中省略调用了
[start][Job.start],接下来 [await][Deferred.await] 会开始执行协程并且等待协程执行结束,
因此我们会得到顺序的行为,但这不是惰性启动的预期用例。
当调用挂起函数计算值的时候
`async(start = CoroutineStart.LAZY)` 用例是标准的 `lazy` 函数的替换方案。
Note that if we have called [await][Deferred.await] in `println` and omitted [start][Job.start] on individual
coroutines, then we would have got the sequential behaviour as [await][Deferred.await] starts the coroutine
execution and waits for the execution to finish, which is not the intended use-case for laziness.
The use-case for `async(start = CoroutineStart.LAZY)` is a replacement for the
standard `lazy` function in cases when computation of the value involves suspending functions.

### async 风格的函数

Expand Down Expand Up @@ -301,7 +301,7 @@ suspend fun doSomethingUsefulTwo(): Int {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-compose-04.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-compose-04.kt)获取完整代码。
<!--- TEST ARBITRARY_TIME
The answer is 42
Expand Down Expand Up @@ -377,7 +377,7 @@ suspend fun doSomethingUsefulTwo(): Int {

</div>

> 你可以点击[这里](../kotlinx-coroutines-core/jvm/test/guide/example-compose-05.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-compose-05.kt)获取完整代码。
从上面的 main 函数的输出可以看出,我们仍然可以同时执行这两个操作:

Expand Down Expand Up @@ -424,7 +424,7 @@ suspend fun failedConcurrentSum(): Int = coroutineScope {

</div>

> 你可以点击这里[这里](../kotlinx-coroutines-core/jvm/test/guide/example-compose-06.kt)获得完整代码
> 可以在[这里](../kotlinx-coroutines-core/jvm/test/guide/example-compose-06.kt)获取完整代码。
注意,当第一个子协程失败的时候第一个 `async` 是如何等待父线程被取消的:
```text
Expand Down
Loading

0 comments on commit e7cd628

Please sign in to comment.