Hi everyone: I want to provide synchronous versio...
# android
s
Hi everyone: I want to provide synchronous version of my asynchronous function, but I can't over load, the function have structure like this. Who can explain, why I can't, and is there any other way to overload function for my case.
suspend fun foo(a: Int, b: Int): Int {
delay(100)
return a + b
}
fun foo(a: Int, b: Int): Result<Int> {
//delay
return Result.success( a + b)
}
👍 1
e
Suspension modifier isn’t part of the function signature as well as return type. Thus in reality you have identical function signatures as it is seen by compiler.
☝️ 1
s
So I need to use completion block here for ResultInt?
e
Copy code
suspend fun foo()

fun fooSync()
or if you wanted,
Copy code
@JvmSynthetic // hide from Java
suspend fun foo()

@Deprecated(
    message = "Use the suspend fun in Kotlin",
    replaceWith = ReplaceWith("foo()"),
    level = DeprecationLevel.ERROR,
)
@JvmName("foo") // name for Java
fun fooSync()
☝️ 2
☝🏿 1