Skip to content

Commit 98193b1

Browse files
committed
Move ulimately scheduler to object
1 parent ff078f8 commit 98193b1

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

scalatest/src/main/scala/org/scalatest/concurrent/Ultimately.scala

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -282,18 +282,6 @@ import java.util.concurrent.{ Executors, TimeUnit, ThreadFactory }
282282
trait Ultimately extends PatienceConfiguration {
283283

284284

285-
private[this] lazy val scheduler = {
286-
val threadFactory = new ThreadFactory {
287-
val inner = Executors.defaultThreadFactory()
288-
def newThread(runnable: Runnable) = {
289-
val thread = inner.newThread(runnable)
290-
thread.setDaemon(true)
291-
thread
292-
}
293-
}
294-
295-
Executors.newSingleThreadScheduledExecutor(threadFactory)
296-
}
297285

298286
/**
299287
* Invokes the passed by-name parameter repeatedly until it either succeeds, or a configured maximum
@@ -452,7 +440,7 @@ trait Ultimately extends PatienceConfiguration {
452440
}
453441
}
454442

455-
scheduler.schedule(task, chillTime, TimeUnit.MILLISECONDS)
443+
Ultimately.scheduler.schedule(task, chillTime, TimeUnit.MILLISECONDS)
456444
promise.future
457445
}
458446
else { // Timed out so return a failed Future
@@ -515,4 +503,17 @@ trait Ultimately extends PatienceConfiguration {
515503
* ...
516504
* </pre>
517505
*/
518-
object Ultimately extends Ultimately
506+
object Ultimately extends Ultimately {
507+
private lazy val scheduler = {
508+
val threadFactory = new ThreadFactory {
509+
val inner = Executors.defaultThreadFactory()
510+
def newThread(runnable: Runnable) = {
511+
val thread = inner.newThread(runnable)
512+
thread.setDaemon(true)
513+
thread
514+
}
515+
}
516+
517+
Executors.newSingleThreadScheduledExecutor(threadFactory)
518+
}
519+
}

0 commit comments

Comments
 (0)