aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/scala/async/run/cps/CPSSpec.scala
blob: 208206f8f9715a5112c4c0c8593c967d000613e0 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Copyright (C) 2012 Typesafe Inc. <http://www.typesafe.com>
 */

package scala.async
package run
package cps

import scala.concurrent.{Future, Promise, ExecutionContext, future, Await}
import scala.concurrent.duration._
import scala.async.continuations.CPSBasedAsync._
import scala.util.continuations._

import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.Test
/*
@RunWith(classOf[JUnit4])
class CPSSpec {

  import ExecutionContext.Implicits.global

  def m1(y: Int): Future[Int] = async {
    val f = future { y + 2 }
    val f2 = future { y + 3 }
    val x1 = await(f)
    val x2 = await(f2)
    x1 + x2
  }

  def m2(y: Int): Future[Int] = async {
    val f = future { y + 2 }
    val res = await(f)
    if (y > 0) res + 2
    else res - 2
  }

  @Test
  def testCPSFallback() {
    val fut1 = m1(10)
    val res1 = Await.result(fut1, 2.seconds)
    assert(res1 == 25, s"expected 25, got $res1")

    val fut2 = m2(10)
    val res2 = Await.result(fut2, 2.seconds)
    assert(res2 == 14, s"expected 14, got $res2")
  }

}
*/