future

    1熱度

    1回答

    我正在實現一個帶有三個類的虛擬程序,以更直觀地參考Future的工作方式。我的問題是,有時程序將被鎖定在同步方法,它不會繼續。我找不到原因。有人能夠發現爲什麼沒有一個戰士會打印「我贏了」的路線嗎?當塊 我的電流輸出: Fighter1 Fighter1已進入同步方法 Fighter2 Fighter2已進入同步方法 的代碼如下。 主要類: import java.util.concurrent.C

    0熱度

    1回答

    我有了這個導入Scala的文件 import scala.concurrent.ExecutionContext.Implicits.global 這正常爲Future我用我在方法精品工程文件。但是,我已經創建了一個用於磁盤IO的獨立方法,並且我有一個新的執行上下文。我希望此方法使用此上下文,而其他方法可以繼續使用默認上下文。我如何保證?我目前做如下 private def testConte

    3熱度

    2回答

    我已經寫了下面的代碼: System.out.println("Main thread:" + Thread.currentThread().getId()); CompletableFuture<Void> future = CompletableFuture.runAsync(() -> { try { System.out.println("Before sleep

    1熱度

    1回答

    我有以下的測試方法 def test() = { val aa = Future{10} map { case x if x%2 == 0 => (x,x) case _ => val kk = Future.failed(BadRequestException("dd")); kk } aa } 如果我刪除case _那麼方法的返回類型是Future[(Int,

    1熱度

    1回答

    我有兩個期貨。我想按順序執行它們。例如: val ec: ExecutionContextExecutor = ExecutionContext.Implicits.global val first=Future.successful(...) val second=Future.successful(...) 第一次完成後,應執行第二次。的問題是,第二應返回Future[Object]不

    0熱度

    1回答

    我有以下代碼: val f0: Future[Seq[Seq[Int]]] = processPrerequisitesDTO.getProcessPrerequisiteIdsByProcessTemplateId(processTemplateId).flatMap(pres => Future.sequence( pres.map(pre => processP

    0熱度

    1回答

    導入Future類時出現錯誤Future is not a member of scala.concurrent。 ~/workspace/experiments $ scala Welcome to Scala version 2.9.2 (OpenJDK 64-Bit Server VM, Java 1.7.0_151). Type in expressions to have them

    0熱度

    1回答

    我是新來玩框架(2.6.x)和斯卡拉。我有一個返回Future [JsValue]的函數。如何在後續函數中使用Future [JsValue]? def getInfo(): Future[JsValue] ={} 以下函數將使用JsValue中的值來計算某些內容。我不得不從json響應中提取一個值。 val currentWeight = (jsValue \ "weight").as[St

    6熱度

    1回答

    與Release不同,以下代碼在使用MSVC在Debug模式下構建時隨機間隔崩潰。 #include <future> using namespace std; int main() { auto l = [](){}; auto f = async(launch::async, l); for (int i = 0; i < 1000000; ++i)

    0熱度

    2回答

    我有一個項目階與http4s 0.15.16a和光滑3.2.1下列步驟操作: 通過REST調用接收一個ID 通過ID來MySlickDAO與響應一個未來 呼叫Await.result(RES,Duration.Inf)在未來返回由MySlickDAO 創建JSON 的問題是,我使用的是Await.re這是不好的做法 有沒有更好的解決方案? 下面的代碼: val service = HttpServ