I’ve got the following problem: here’s an interfac...
# coroutines
e
I’ve got the following problem: here’s an interface called `Source`:
Copy code
interface Source : Closeable {
  @Throws(IOException::class)
  fun read(sink: Buffer, byteCount: Long): Long
}
I’m declaring
SuspendingSource
like this:
Copy code
interface SuspendingSource : Source {
  @Throws(IOException::class)
  override suspend fun read(sink: Buffer, byteCount: Long): Long
}
which doesn’t compile because of
Conflicting overloads
. Is it forbidden to override non-suspend functions with suspend ones?
d
Yes, it is forbidden. Since the anyone calling
Source.read
doesn't not know to suspend.
e
Ah, makes sense
b
It’s also quite intuitive if you look at the generated bytecode of a suspend function. They work by passing a hidden extra argument which tells the function where to resume.