Skip to content

Instantly share code, notes, and snippets.

@notyy
Created February 1, 2018 03:50
Show Gist options
  • Save notyy/73a7562f103a6d5a77c097c40cba7a73 to your computer and use it in GitHub Desktop.
Save notyy/73a7562f103a6d5a77c097c40cba7a73 to your computer and use it in GitHub Desktop.
future in different thread
package concurrency.future
import com.typesafe.scalalogging.StrictLogging
import scala.concurrent.{Await, Future}
import scala.concurrent.duration._
import scala.language.postfixOps
import scala.concurrent.ExecutionContext.Implicits.global
object FutureAwait extends App with StrictLogging {
logger.info("now")
def doSomethingInFuture: Future[Int] = Future {
logger.info("this is in future")
1
}
val rs = Await.result(doSomethingInFuture, 1 second)
logger.info(s"rs is $rs")
}
@jasonqu
Copy link

jasonqu commented Feb 1, 2018

赞, 可以用 ExecutionContext.fromExecutor 简化一下:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment