本文整理汇总了Scala中com.google.common.util.concurrent.FutureCallback类的典型用法代码示例。如果您正苦于以下问题:Scala FutureCallback类的具体用法?Scala FutureCallback怎么用?Scala FutureCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FutureCallback类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: GuavaFutures
//设置package包名称以及导入依赖的类
package akka.stream.alpakka.cassandra
import com.google.common.util.concurrent.{FutureCallback, Futures, ListenableFuture}
import scala.concurrent.{Future, Promise}
private[cassandra] object GuavaFutures {
implicit final class GuavaFutureOpts[A](val guavaFut: ListenableFuture[A]) extends AnyVal {
def asScala(): Future[A] = {
val p = Promise[A]()
val callback = new FutureCallback[A] {
override def onSuccess(a: A): Unit = p.success(a)
override def onFailure(err: Throwable): Unit = p.failure(err)
}
Futures.addCallback(guavaFut, callback)
p.future
}
}
}
开发者ID:akka,项目名称:alpakka,代码行数:20,代码来源:GuavaFutures.scala
示例2: toAsyncF
//设置package包名称以及导入依赖的类
package spinoco.fs2
import com.google.common.util.concurrent.{FutureCallback, Futures, ListenableFuture}
import fs2.util.Async
package object cassandra {
implicit def toAsyncF[F[_],A](f:ListenableFuture[A])(implicit F:Async[F]):F[A] = {
F.async { cb =>
F.pure(Futures.addCallback(f, new FutureCallback[A] {
def onFailure(t: Throwable): Unit = { cb(Left(t))}
def onSuccess(result: A): Unit = { cb(Right(result)) }
}))
}
}
}
开发者ID:Spinoco,项目名称:fs2-cassandra,代码行数:19,代码来源:cassandra.scala
示例3: executeWithAsynch
//设置package包名称以及导入依赖的类
package net.cassandratest
import com.datastax.driver.core.{ResultSetFuture, ResultSet, Session, Statement}
import com.google.common.util.concurrent.{ListeningExecutorService, FutureCallback, Futures}
import scala.concurrent.{ Promise, Future }
trait FutureHelper {
def executeWithAsynch(st: Statement)(implicit session: Session, executor: ListeningExecutorService): Future[ResultSet] = {
execute(st).future
}
private def execute(st: Statement)(implicit session: Session, executor: ListeningExecutorService): Promise[ResultSet] = {
val promise = Promise[ResultSet]()
val future: ResultSetFuture = session.executeAsync(st)
val callback = new FutureCallback[ResultSet] {
def onSuccess(result: ResultSet): Unit = {
promise success result
}
def onFailure(err: Throwable): Unit = {
promise failure err
}
}
Futures.addCallback(future, callback, executor)
promise
}
}
开发者ID:giampaolotrapasso,项目名称:cassandratest,代码行数:33,代码来源:FutureHelper.scala
示例4: RichListenableFuture
//设置package包名称以及导入依赖的类
package recipestore.misc
import com.google.common.util.concurrent.{FutureCallback, Futures, ListenableFuture}
import scala.concurrent.{Future, Promise}
object RichListenableFuture {
implicit class RichListenableFuture[T](lf: ListenableFuture[T]) {
def asScala: Future[T] = {
val p = Promise[T]()
Futures.addCallback(lf, new FutureCallback[T] {
def onFailure(t: Throwable): Unit = p failure t
def onSuccess(result: T): Unit = p success result
})
p.future
}
}
}
开发者ID:prad-a-RuntimeException,项目名称:semantic-store,代码行数:22,代码来源:RichListenableFuture.scala
注:本文中的com.google.common.util.concurrent.FutureCallback类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论