Karthik Periasami
06/11/2021, 6:29 PMinterface RestApi {
fun get()
fun post()
fun put()
fun delete()
}
interface NewRestApi {
suspend fun get()
suspend fun post()
suspend fun put()
suspend fun delete()
}
I am adding a feature in my rest client library to support suspend functions. What is the recommended prefix for suspend method names? I need something to differentiate between the non-suspend functions, to avoid misunderstanding. Any ideas are welcome, I suck at naming.Francesc
06/11/2021, 6:58 PMblockingXYZ
as in blockingGet
, blockingPost
wasyl
06/11/2021, 6:59 PMKarthik Periasami
06/11/2021, 7:00 PMget
is used.ephemient
06/11/2021, 7:52 PM@JvmName("get") fun blockingGet()
might help if you want to maintain binary compatibility with existing users (although this would be a source compatibility breakage)interface RestApi {
@Deprecated("Use blockingGet", ReplaceWith("blockingGet()"), DeprecationLevel.ERROR)
fun get()
@Suppress("DEPRECATION")
fun blockingGet() = get()
}
will maintain ABI compatibility for existing users. new users use the new function name, and eventually you may be able to hide or remove the old function nameTwoClocks
06/11/2021, 8:28 PMget
and getSuspend
. The getSuspend
must be called from a async
block, and depending on what get
does the compiler can also warn you if your making blocking calls from async
code.async
code I'll use getNoSuspend
. But as far as I know there is no convention.ephemient
06/11/2021, 8:43 PM@Throws(IOException::class)
it'll warn about calling from suspending context, if the dispatcher isn't known to be IO... many issues such as https://youtrack.jetbrains.com/issue/KTIJ-838 etc.
2. IMO, suspend fun getSuspend()
is too much stutterursus
06/12/2021, 2:00 AMawait
. Also, I wouldn't put any notation on it, you cant call suspend function from a nonsuspending context anyways