This works for me, must be your use of thunk-to-function parameters:
scala object Concurrency {
| import java.util.concurrent.Executors
| import akka.dispatch.ExecutionContexts
| import akka.actor._
| import scala.concurrent._
| import scala.concurrent.duration._
| object Log { def warn(s: String): Unit = System.err.println(s) }
| private val system = ActorSystem(system, defaultExecutionContext
= Some(ExecutionContexts.fromExecutor(Executors.newCachedThreadPool(
| import system.dispatcher
| private val scheduler = system.scheduler
| Log.warn(starting up actor system)
| Future { Log.warn(runNow works) }
| scheduler.scheduleOnce(3.seconds)(Log.warn(scheduleOnce works))
| }
defined object Concurrency
scala Concurrency.toString
starting up actor system
runNow works
res0: String = Concurrency$@417781bc
scala scheduleOnce works
On Sun, Apr 26, 2015 at 9:50 PM, Ian Nowland ian.nowl...@gmail.com wrote:
I've been following various example code I've found online, but no matter
how I rearrange it, I can't seem to get a simple scheduler example to work.
This is my current code:
object Concurrency extends Loggable {
private val system = ActorSystem(system, defaultExecutionContext =
Some(ExecutionContexts.fromExecutor(Executors.newCachedThreadPool(
import system.dispatcher
private val scheduler = system.scheduler
Log.warn(starting up actor system)
def runNow(f: = () = Unit):Unit =
Future {f()}
def scheduleOnce(duration:FiniteDuration, f: = () = Unit):Unit = {
scheduler.scheduleOnce(duration)(() = runNow(f))
}
runNow(() = Log.warn(runNow works))
scheduleOnce(FiniteDuration(3,TimeUnit.SECONDS),() =
Log.warn(scheduleOnce works))
}
When I run this, I see my runNow works go off, but not my
scheduleOnce. What am I missing?
--
Read the docs: http://akka.io/docs/
Check the FAQ:
http://doc.akka.io/docs/akka/current/additional/faq.html
Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups
Akka User List group.
To unsubscribe from this group and stop receiving emails from it, send an
email to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
--
Cheers,
√
--
Read the docs: http://akka.io/docs/
Check the FAQ:
http://doc.akka.io/docs/akka/current/additional/faq.html
Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups Akka
User List group.
To unsubscribe from this group and stop receiving emails from it, send an email
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.