Consider the following sync and async interfaces:
interface Out {
fun write(data: Byte)
}
interface AsyncOut {
suspend fun write(data: Byte)
}
Both interface have the same semantics, only the functions in AsyncOut are suspend functions. Is there a generic way to have a class or a function that works with both interfaces? e.g.
fun writeAll(out: Out|AsyncOut)
with out either the Out or the AsyncOut interface. In the later case the writeAll function would have to becomes a suspend function. The writeAll method would be exactly the same otherwise.
Is there a way to reuse the code in writeAll to work with suspend and non-suspend interfaces?