Skip to content

Commit

Permalink
Permit setting deadline per-call
Browse files Browse the repository at this point in the history
Adds a setDeadline method to the request builder, so that it can optionally be
specified per call.
  • Loading branch information
longshorej committed Sep 27, 2023
1 parent 77b8e49 commit 0b901c4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
21 changes: 19 additions & 2 deletions runtime/src/main/scala/akka/grpc/internal/RequestBuilderImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

package akka.grpc.internal

import java.util.concurrent.CompletionStage

import java.util.concurrent.{ CompletionStage, TimeUnit }
import akka.NotUsed
import akka.annotation.{ InternalApi, InternalStableApi }
import akka.dispatch.ExecutionContexts
import akka.grpc.scaladsl.SingleResponseRequestBuilder
import akka.grpc.{ GrpcClientSettings, GrpcResponseMetadata, GrpcServiceException, GrpcSingleResponse }
import akka.stream.{ Graph, Materializer, SourceShape }
import akka.stream.javadsl.{ Source => JavaSource }
Expand All @@ -17,6 +17,7 @@ import akka.util.ByteString
import io.grpc._

import scala.compat.java8.FutureConverters._
import scala.concurrent.duration.Duration
import scala.concurrent.{ ExecutionContext, Future }

/**
Expand Down Expand Up @@ -52,6 +53,14 @@ final class ScalaUnaryRequestBuilder[I, O](

override def withHeaders(headers: MetadataImpl): ScalaUnaryRequestBuilder[I, O] =
new ScalaUnaryRequestBuilder[I, O](descriptor, channel, defaultOptions, settings, headers)

override def setDeadline(deadline: Duration): SingleResponseRequestBuilder[I, O] =
new ScalaUnaryRequestBuilder[I, O](
descriptor,
channel,
defaultOptions.withDeadlineAfter(deadline.toMillis, TimeUnit.MILLISECONDS),
settings,
headers)
}

/**
Expand Down Expand Up @@ -152,6 +161,14 @@ final class ScalaClientStreamingRequestBuilder[I, O](

override def withHeaders(headers: MetadataImpl): ScalaClientStreamingRequestBuilder[I, O] =
new ScalaClientStreamingRequestBuilder[I, O](descriptor, channel, defaultOptions, settings, headers)

override def setDeadline(deadline: Duration): ScalaClientStreamingRequestBuilder[I, O] =
new ScalaClientStreamingRequestBuilder[I, O](
descriptor,
channel,
defaultOptions.withDeadlineAfter(deadline.toMillis, TimeUnit.MILLISECONDS),
settings,
headers)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import akka.stream.scaladsl.Source
import akka.util.ByteString

import scala.concurrent.Future
import scala.concurrent.duration.Duration

/**
* Request builder for requests providing per call specific metadata capabilities in
Expand Down Expand Up @@ -48,6 +49,12 @@ trait SingleResponseRequestBuilder[Req, Res] {
* Invoke the gRPC method with the additional metadata added and provide access to response metadata
*/
def invokeWithMetadata(request: Req): Future[GrpcSingleResponse[Res]]

/**
* Set the deadline for this call
* @return A new request builder, that will use the supplied deadline when invoked
*/
def setDeadline(deadline: Duration): SingleResponseRequestBuilder[Req, Res]
}

/**
Expand Down

0 comments on commit 0b901c4

Please sign in to comment.