Created
November 22, 2018 21:36
-
-
Save vichu/49a8909885002e972d48a78b4b372bb7 to your computer and use it in GitHub Desktop.
An example to simulate a network call
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
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