Skip to content

Instantly share code, notes, and snippets.

@parth-patil
Created June 17, 2015 21:07
Show Gist options
  • Save parth-patil/17ba1ece39e8c79b3389 to your computer and use it in GitHub Desktop.
Save parth-patil/17ba1ece39e8c79b3389 to your computer and use it in GitHub Desktop.
import com.twitter.util.{ Future => TFuture, _}
object Tester extends App {
def test1(): Unit = {
implicit val timer: Timer = new ScheduledThreadPoolTimer()
val startTime = System.currentTimeMillis()
val longProcess: TFuture[String] = TFuture { Thread.sleep(1000); "done" }
longProcess.raiseWithin(Duration.fromMilliseconds(100))
.onSuccess { _ => val elapsed = System.currentTimeMillis() - startTime; println(s"long process Success, elapsed = $elapsed")}
.onFailure { e: Throwable => println(s"Timedout !! e = " + e.getMessage)}
}
test1()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment