You need to split sendFuture into two function and use map on the result (which is a future) of the first function, but i don't know where you get this stuff, that's not Scala Future. Anyway the logic is simple:

The first part of the function should contain a promise, which would expect the result of your callback (everything belongs to Scala implementation of Futures), e.g:

def computeFirstpart(input: String): Future[String] = {
  val promise: Promise[String] = Promise()
  // do something with your string
  callback.onComplete { case v => promise.complete(v) }

This part returns the result of your callback. Now you can attach more computations:

def sendFuture(input: String): Future[String] = {
  computeFirstPart(input) flatMap { resultOfFirstPart =>
    // do what you need
    result // NOTE 1

NOTE 1 The result should be in Future context, you are returning simple type (like String) use map, not flatMap. Then use it in your route structure:

post {
    entity(as[String]) { input =>
        onComplete(sendFuture(input)) {
          case Success(result) =>
            complete("received: " + result)
          case Failure(ex) => 
            complete("An error occurred: " + ex.getMessage())

Related Query