Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 59f0efce authored by Charlie Boutier's avatar Charlie Boutier
Browse files

PandoraServer: Properly cancel the job

Properly cancel the job when the stream is cancel.

Test: run abdtd
Bug: 274685676
Change-Id: Ic49b03a3d29d470a7c7331ff48752cd70efde1f1
parent 7630740b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -167,6 +167,7 @@ fun <T, U> grpcBidirectionalStream(
): StreamObserver<T> {

  val inputChannel = Channel<T>()
  val serverCallStreamObserver = responseObserver as ServerCallStreamObserver<T>

  val job =
    scope.launch {
@@ -184,6 +185,8 @@ fun <T, U> grpcBidirectionalStream(
        .launchIn(this)
    }

  serverCallStreamObserver.setOnCancelHandler { job.cancel() }

  return object : StreamObserver<T> {
    override fun onNext(req: T) {
      // Note: this should be made a blocking call, and the handler should run in a separate thread