rspec/rules/S6318/kotlin/rule.adoc

26 lines
816 B
Plaintext
Raw Normal View History

2021-07-28 16:04:48 +02:00
The `suspend` function modifier is used to mark a function which might take some time to execute and could suspend the caller coroutine. The location where such function is called is a "suspension point". Functions marked as `suspend` ("suspending functions") should themselves contain at least one suspension point, otherwise it makes no sense to mark it as `suspend`
This rule reports an issue if a function with `suspend` modifier has no calls to other `suspend` functions inside its body.
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,kotlin]
----
suspend fun function() { // Noncompliant, redundant 'suspend' modifier
println("Hello!")
}
----
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,kotlin]
----
fun function() {
println("Hello!")
}
----
== See
* https://kotlinlang.org/docs/coroutines-guide.html[Coroutines guide]