Thread Sleep for Specified Duration
Inspect one language lane at a time so line-level text and code deltas stay readable.
Diff Lane
English
0 modified sections0 code block delta0 anchor delta
Diff Lane
中文
1 modified sections0 code block delta0 anchor delta
modified线程睡眠指定时长 sleeptext+1 line
v1.0.5
Section Text
1
`sleep` 函数会阻塞当前运行的线程,该线程会主动睡眠一段时间,之后再恢复执行,其参数类型为 Duration 类型。函数原型为:2
3
4
> **注意:**5
>6
> 如果 `dur` <= Duration.Zero, 那么当前线程只会让出执行资源,并不会进入睡眠。7
8
以下是使用 `sleep` 的示例:9
10
<!-- verify -->11
12
13
输出结果如下:Code 1 · cangjie
1
func sleep(dur: Duration): Unit // Sleep for at least `dur`.Code 2 · cangjie
1
main(): Int64 {2
println("Hello")3
sleep(Duration.second) // sleep for 1s.4
println("World")5
return 06
}Code 3 · text
1
Hello2
Worldv1.1.0
Section Text
1
`sleep` 函数会阻塞当前运行的线程,该线程会主动睡眠一段时间,之后再恢复执行,其参数类型为 Duration 类型。函数原型为:2
3
<!-- code_no_check -->4
5
6
> **注意:**7
>8
> 如果 `dur` <= Duration.Zero, 那么当前线程只会让出执行资源,并不会进入睡眠。9
10
以下是使用 `sleep` 的示例:11
12
<!-- verify -->13
14
15
输出结果如下:Code 1 · cangjie
1
func sleep(dur: Duration): Unit // Sleep for at least `dur`.Code 2 · cangjie
1
main(): Int64 {2
println("Hello")3
sleep(Duration.second) // sleep for 1s.4
println("World")5
return 06
}Code 3 · text
1
Hello2
World