Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate execution context from scheduling tasks in the future
- Loading branch information
Showing
9 changed files
with
54 additions
and
59 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
soda-consumer-scala/src/main/scala/com/socrata/future/ExecutionContextTimer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.socrata.future | ||
|
||
import java.util.{TimerTask, Timer} | ||
import scala.concurrent.{Promise, Future, ExecutionContext} | ||
import scala.concurrent.duration.FiniteDuration | ||
import scala.util.Try | ||
|
||
class ExecutionContextTimer(val timer: Timer) { | ||
def in[T](duration: FiniteDuration)(f: => T)(implicit ctx: ExecutionContext): Future[T] = { | ||
val promise = Promise[T]() | ||
val task = new TimerTask { | ||
def run() { | ||
ctx.execute(new Runnable { | ||
def run() { | ||
promise.complete(Try(f)) | ||
} | ||
}) | ||
} | ||
} | ||
timer.schedule(task, duration.toMillis) | ||
promise.future | ||
} | ||
} | ||
|
||
object ExecutionContextTimer { | ||
def globalTimer = Implicits.globalTimer | ||
object Implicits { | ||
implicit lazy val globalTimer = new ExecutionContextTimer(new Timer(true)) | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
soda-consumer-scala/src/main/scala/com/socrata/future/ScheduledExecutionContext.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters