
r.dispatch.dispatch-core_2.11.0.11.3.source-code.sleep.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dispatch-core_2.11 Show documentation
Show all versions of dispatch-core_2.11 Show documentation
Core Dispatch module wrapping async-http-client
package dispatch
import org.jboss.netty.util.{TimerTask, Timeout, Timer}
import scala.concurrent.{ExecutionContext}
import scala.concurrent.duration.Duration
import java.util.{concurrent => juc}
object SleepFuture {
def apply[T](d: Duration)(todo: => T)
(implicit timer: Timer,
executor: ExecutionContext) = {
val promise = scala.concurrent.Promise[T]()
val sleepTimeout = timer.newTimeout(new TimerTask {
def run(timeout: Timeout) {
promise.complete(util.Try(todo))
}
}, d.length, d.unit)
promise.future
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy