本文整理汇总了Scala中java.util.concurrent.CompletableFuture类的典型用法代码示例。如果您正苦于以下问题:Scala CompletableFuture类的具体用法?Scala CompletableFuture怎么用?Scala CompletableFuture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CompletableFuture类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: TimeServiceImpl
//设置package包名称以及导入依赖的类
package time.impl
import time.api.TimeService
import com.lightbend.lagom.javadsl.api.ServiceCall
import akka.NotUsed
import java.util.concurrent.CompletableFuture
import java.util.concurrent.CompletionStage
import java.time.LocalTime
import java.time.ZoneId
class TimeServiceImpl extends TimeService{
override def timeAt(tz: String): ServiceCall[NotUsed, String] = {
new ServiceCall[NotUsed, String] {
override def invoke(obj: NotUsed) : CompletionStage[String] = {
val c = new CompletableFuture[String]
c.complete(LocalTime.now(ZoneId.of(tz, ZoneId.SHORT_IDS)).toString)
c
}
}
}
}
开发者ID:oswaldo,项目名称:lagom-scala-scalajs-scalatags,代码行数:27,代码来源:TimeServiceImpl.scala
示例2: CalculatorServiceImpl
//设置package包名称以及导入依赖的类
package io.scalac.lagom.calculator
import java.util.concurrent.CompletableFuture
import javax.inject.Inject
import akka.NotUsed
import com.lightbend.lagom.javadsl.api.ServiceCall
import io.scalac.lagom.calculator.api.{CalculatedValue, CalculatorService}
import io.scalac.lagom.rates.api.{ExchangeRatesService, ExchangeRatio}
import io.scalac.lagom.utils.Implicits._
import io.scalac.lagom.utils.ServerError
class CalculatorServiceImpl @Inject()(exchangeRatesService: ExchangeRatesService) extends CalculatorService {
def calculate(fromValue: BigDecimal, fromUnit: String, toUnit: String): ServiceCall[NotUsed, CalculatedValue] =
(_: NotUsed) => {
exchangeRatesService.getExchangeRate(fromUnit, toUnit).invoke().thenCompose(
(v1: ExchangeRatio) => v1.ratio match {
case Some(ratio) => CompletableFuture.completedFuture[CalculatedValue](CalculatedValue(ratio, toUnit))
case _ => {
val v = new CompletableFuture[CalculatedValue]()
v.completeExceptionally(ServerError(s"Could not retrive a ratio for $fromUnit-$toUnit"))
v
}
}
)
}
}
开发者ID:ScalaConsultants,项目名称:lagom-scala-post-example,代码行数:28,代码来源:CalculatorServiceImpl.scala
示例3: EhPublisher
//设置package包名称以及导入依赖的类
package onextent.eventhubs.publisher
import java.util.concurrent.CompletableFuture
import com.microsoft.azure.eventhubs.EventHubClient
import com.microsoft.azure.servicebus.ConnectionStringBuilder
import com.typesafe.config.ConfigFactory
object EhPublisher {
private val config = ConfigFactory.load().getConfig("main")
private val namespaceName = config.getString("eventhubs.eventHubNamespace")
private val eventHubName = config.getString("eventhubs.eventHubName")
private val sasKeyName = config.getString("eventhubs.policyName")
private val sasKey = config.getString("eventhubs.policyKey")
private val connStr = new ConnectionStringBuilder(namespaceName,
eventHubName,
sasKeyName,
sasKey)
val f: CompletableFuture[EventHubClient] =
EventHubClient.createFromConnectionString(connStr.toString)
final val ehClient: EventHubClient = f.join()
}
开发者ID:navicore,项目名称:EventHubsKafkaPublisher,代码行数:25,代码来源:EhPublisher.scala
注:本文中的java.util.concurrent.CompletableFuture类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论