scala - How to do: Try {block of code} for X duration and catch {Exceptions, such as Timeout}? -
alright title little obscure since unsure how word it, trying try-catch statement timeout... here's pseudo-code may describe i'm trying do:
try (10 seconds) { *make connection , things* } catch { case ex1: timeoutexception => *do something* case ex2: exception => *do else* }
currently there bug in hardware i'm working request connection never gets response back, sits there , doesn't catch exceptions. since it's bug (that should temporary), don't want manipulate architecture of application (specifically not want create new actor account small) , ideal if implement pseudo-code within scope of class.
so question how implement pseudo-code above within scope of class it's in?
let me know if unclear! thank you!
try:
import scala.concurrent._ import executioncontext.implicits.global val f = future { // make connection , things } try { await.result(f, 10 seconds); } catch { case e: timeoutexception => // case _ => // else }
more info: futures , promises
Comments
Post a Comment