blob: dd649f46636ff1b4296c6d84fc3522fbbba294e6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
package scala.async.run
import org.junit.Test
import scala.async.Async._
import scala.concurrent._
import scala.concurrent.duration._
import ExecutionContext.Implicits._
class SyncOptimizationSpec {
@Test
def awaitOnCompletedFutureRunsOnSameThread: Unit = {
def stackDepth = Thread.currentThread().getStackTrace.size
val future = async {
val thread1 = Thread.currentThread
val stackDepth1 = stackDepth
val f = await(Future.successful(1))
val thread2 = Thread.currentThread
val stackDepth2 = stackDepth
assert(thread1 == thread2)
assert(stackDepth1 == stackDepth2)
}
Await.result(future, 10.seconds)
}
}
|