blob: 745d2d1a15fa6d799fa0e7ad5508cd2102c49351 (
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
|
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
package scala.concurrent
package default
import scala.util.Duration
private[concurrent] final class SchedulerImpl extends Scheduler {
private val timer =
new java.util.Timer(true) // the associated thread runs as a daemon
def schedule(delay: Duration, frequency: Duration)(thunk: => Unit): Cancellable = ???
def scheduleOnce(delay: Duration, task: Runnable): Cancellable = {
val timerTask = new java.util.TimerTask {
def run(): Unit =
task.run()
}
timer.schedule(timerTask, delay.toMillis)
new Cancellable {
def cancel(): Unit =
timerTask.cancel()
}
}
def scheduleOnce(delay: Duration)(task: => Unit): Cancellable = {
val timerTask = new java.util.TimerTask {
def run(): Unit =
task
}
timer.schedule(timerTask, delay.toMillis)
new Cancellable {
def cancel(): Unit =
timerTask.cancel()
}
}
}
|