All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.chengpohi.api.dsl.DSLExecutor.scala Maven / Gradle / Ivy

The newest version!
package com.github.chengpohi.api.dsl

import org.elasticsearch.action.{ActionListener, ListenableActionFuture}

import scala.concurrent.{Future, Promise}

/**
  * elasticdsl
  * Created by chengpohi on 6/28/16.
  */

trait DSLExecutor {
  implicit def buildFuture[A](f: ActionListener[A] => Any): Future[A] = {
    val p = Promise[A]()
    f(new ActionListener[A] {
      def onFailure(e: Exception): Unit = p.tryFailure(e)

      def onResponse(resp: A): Unit = p.trySuccess(resp)
    })
    p.future
  }

  implicit def buildFuture[A](f: ListenableActionFuture[A]): Future[A] = {
    val p = Promise[A]()
    f.addListener(new ActionListener[A] {
      def onFailure(e: Exception): Unit = p.tryFailure(e)

      def onResponse(resp: A): Unit = p.trySuccess(resp)
    })
    p.future
  }

  object DSL {
    def apply[A](f: Definition[A]): Future[A] = f.execute
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy