Skip to content

Instantly share code, notes, and snippets.

@richard-gibson
Last active February 2, 2021 12:59
Show Gist options
  • Save richard-gibson/883e15d7cc232aecf1b6712cdc129c29 to your computer and use it in GitHub Desktop.
Save richard-gibson/883e15d7cc232aecf1b6712cdc129c29 to your computer and use it in GitHub Desktop.
Possible way to capture tracing for anonymous functions
def trace[U, V](
functionName: String
)(func: U => V)(implicit txnExecutionContext: TxnExecutionContext): U => V =
new Function1[U, V] {
// set functionName, call trace async here
def apply(u: U): V = {
txnExecutionContext.token.link()
func(u)
}
}
// Function could be called as
Future(1)
.flatMap(trace("increment")(x => x + 1))
.map(trace("decrement")(y => y - 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment