Skip to content

Instantly share code, notes, and snippets.

@vkostyukov
Last active March 11, 2016 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkostyukov/750196650f381e24c7aa to your computer and use it in GitHub Desktop.
Save vkostyukov/750196650f381e24c7aa to your computer and use it in GitHub Desktop.
TimeEndpoint
import io.finch._
import com.twitter.finagle.stats._
// See https://github.com/finagle/finch/issues/552
def time[A](stat: Stat, e: Endpoint[A]): Endpoint[A] = new Endpoint[A] {
def apply(: Input): Endpoint.Result[A] = {
e(i).map {
case (remainder, output) => remainder -> output.map { f =>
Stat.timeFuture(stat)(f)
}
}
}
}
// Usage
val e = get("users") {
Ok("users")
}
val eTimed = time(statsReceiver.stat(...), e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment