Guest User

Untitled

a guest
Sep 9th, 2020
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.59 KB | None | 0 0
  1. val content = object : OutgoingContent.WriteChannelContent() {
  2.     override suspend fun writeTo(channel: ByteWriteChannel) {
  3.         val stream = channel.toOutputStream()
  4.         try {
  5.             withContext(Dispatchers.IO) {
  6.                 stream.run {
  7.                     write(1)
  8.                     write(2)
  9.                     flush()
  10.                     TODO("oops!")
  11.                 }
  12.             }
  13.         } catch (e: Throwable) {
  14.             channel.close(e)
  15.             throw e
  16.         } finally {
  17.             channel.close()
  18.         }
  19.     }
  20. }
  21. context.respond(content)
Advertisement
Add Comment
Please, Sign In to add comment