aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/scala/async/AsyncUtils.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/scala/async/AsyncUtils.scala')
-rw-r--r--src/main/scala/scala/async/AsyncUtils.scala36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/main/scala/scala/async/AsyncUtils.scala b/src/main/scala/scala/async/AsyncUtils.scala
new file mode 100644
index 0000000..19e9d92
--- /dev/null
+++ b/src/main/scala/scala/async/AsyncUtils.scala
@@ -0,0 +1,36 @@
+/**
+ * Copyright (C) 2012 Typesafe Inc. <http://www.typesafe.com>
+ */
+package scala.async
+
+import scala.reflect.macros.Context
+
+/*
+ * @author Philipp Haller
+ */
+trait AsyncUtils {
+
+ val verbose = false
+
+ protected def vprintln(s: Any): Unit = if (verbose)
+ println("[async] "+s)
+
+ /* Symbol of the `Async.await` method in context `c`.
+ */
+ protected def awaitSym(c: Context): c.universe.Symbol = {
+ val asyncMod = c.mirror.staticModule("scala.async.Async")
+ val tpe = asyncMod.moduleClass.asType.toType
+ tpe.member(c.universe.newTermName("await"))
+ }
+
+ protected def awaitCpsSym(c: Context): c.universe.Symbol = {
+ val asyncMod = c.mirror.staticModule("scala.async.Async")
+ val tpe = asyncMod.moduleClass.asType.toType
+ tpe.member(c.universe.newTermName("awaitCps"))
+ }
+
+ private var cnt = 0
+ protected[async] def freshString(prefix: String): String =
+ prefix + "$async$" + { cnt += 1; cnt }
+
+}