Last active
February 2, 2021 12:59
-
-
Save richard-gibson/883e15d7cc232aecf1b6712cdc129c29 to your computer and use it in GitHub Desktop.
Possible way to capture tracing for anonymous functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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