Roiocam commented on code in PR #1424:
URL: https://github.com/apache/pekko/pull/1424#discussion_r1729514685


##########
actor/src/main/scala/org/apache/pekko/pattern/FutureTimeoutSupport.scala:
##########
@@ -87,4 +86,64 @@ trait FutureTimeoutSupport {
       }
       p
     }
+
+  /**
+   * Returns a [[scala.concurrent.Future]] that will be completed with a 
[[TimeoutException]]
+   * if the provided value is not completed within the specified duration.
+   */
+  def timeout[T](duration: FiniteDuration, using: Scheduler)(value: => 
Future[T])(
+      implicit ec: ExecutionContext): Future[T] = {
+    val future =
+      try value
+      catch {
+        case NonFatal(t) => Future.failed(t)
+      }
+    future.value match {
+      case Some(_) => future
+      case None => // not completed yet
+        val p = Promise[T]()
+        val timeout = using.scheduleOnce(duration) {
+          p.tryFailure(new TimeoutException(s"Timeout of $duration expired"))
+          if (future.isInstanceOf[CompletableFuture[T]]) {

Review Comment:
   cool feature, but seem like it doesn't support scala future, because it 
haven't cancel/interrrupt method



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org
For additional commands, e-mail: notifications-h...@pekko.apache.org

Reply via email to