Skip to content

Instantly share code, notes, and snippets.

@vichu
Created November 22, 2018 21:36
Show Gist options
  • Save vichu/49a8909885002e972d48a78b4b372bb7 to your computer and use it in GitHub Desktop.
Save vichu/49a8909885002e972d48a78b4b372bb7 to your computer and use it in GitHub Desktop.
An example to simulate a network call
import scala.concurrent.{ExecutionContext, Future}
class NetworkCallExample {
implicit val ec: ExecutionContext = ExecutionContext.Implicits.global
private def getResponseFromServer(url: String): Future[Int] = {
Future {
Thread.sleep(5000)
10
}
}
// Dummy method to simulate a network call
def statusOfSomeOtherResponse(url: String): Future[Int] = {
println("Sending out request to some other url")
Future {
Thread.sleep(1000)
200
}
}
//Another dummy call
def lengthOfTheResponse(url: String): Future[Int] = {
println("Sending out request asynchronously to the server")
getResponseFromServer(url)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment