Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

378
Views
@Around aspect and Kotlin suspended function

I try to understand how to create an @Around aspect for a Kotlin’s suspended function (for example, to measure time spent in this function, or for a custom @Transactional aspect):

@Timed("my-timer")
suspend fun test() {
    println("before")
    delay(50) // invokes ProceedingJoinPoint#proceed() before this line
    println("after")
}

Since this function has a suspend function call, the @Around aspect’s proceed function will be invoked right before delay() call. But obviously I’d like to measure full time spent in the function.

What is the right way to solve it? Maybe I can somehow subscribe on the last continuation in the method, or smth like that?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I think you can solve your problem easily, if you want to measure, the execution time of function, you can do it using built-in functionality like this:

val time = measureTimeMillis {
    // yourSuperFunc()
}

Also, you can use measureNanoTime. For full reference look at here.

over 4 years ago · Santiago Trujillo Report

0

This is tracked by https://github.com/spring-projects/spring-framework/issues/22462 and will most likely be fixed in 5.3

The same issue happens for @Transactional.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!