Github user JoshRosen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7385#discussion_r34755173
  
    --- Diff: core/src/main/scala/org/apache/spark/FutureAction.scala ---
    @@ -116,55 +123,27 @@ class SimpleFutureAction[T] private[spark](jobWaiter: 
JobWaiter[_], resultFunc:
       }
     
       override def ready(atMost: Duration)(implicit permit: CanAwait): 
SimpleFutureAction.this.type = {
    -    if (!atMost.isFinite()) {
    -      awaitResult()
    -    } else jobWaiter.synchronized {
    -      val finishTime = System.currentTimeMillis() + atMost.toMillis
    -      while (!isCompleted) {
    -        val time = System.currentTimeMillis()
    -        if (time >= finishTime) {
    -          throw new TimeoutException
    -        } else {
    -          jobWaiter.wait(finishTime - time)
    -        }
    -      }
    -    }
    +    jobWaiter.ready(atMost)(permit)
         this
       }
     
       @throws(classOf[Exception])
       override def result(atMost: Duration)(implicit permit: CanAwait): T = {
    -    ready(atMost)(permit)
    -    awaitResult() match {
    -      case scala.util.Success(res) => res
    -      case scala.util.Failure(e) => throw e
    -    }
    +    jobWaiter.result(atMost)(permit) // Throws exception if the job failed.
    --- End diff --
    
    Let's see... jobWaiter.result delegates to the job waiter's 
promise.future.result.
    
    Here, I think we have an instance of DefaultPromise, whose `result` 
(https://github.com/scala/scala/blob/v2.10.4/src/library/scala/concurrent/impl/Promise.scala#L222)
 is implemented in terms of `ready` 
(https://github.com/scala/scala/blob/v2.10.4/src/library/scala/concurrent/impl/Promise.scala#L218),
 which in turn is implemented using the internal `tryAwait` method: 
https://github.com/scala/scala/blob/v2.10.4/src/library/scala/concurrent/impl/Promise.scala#L194
    
    It looks like this is implemented by scheduling an `onComplete` callback 
which updates a latch.  This callback runs on `Future`'s 
InternalCallbackExecutor: 
https://github.com/scala/scala/blob/v2.10.4/src/library/scala/concurrent/Future.scala#L590


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to