![Structured Concurrency in Practice: CoroutineScope vs StructuredTaskScope [Part 5]](/_next/image?url=https%3A%2F%2Fmedia2.dev.to%2Fdynamic%2Fimage%2Fwidth%3D1200%2Cheight%3D627%2Cfit%3Dcover%2Cgravity%3Dauto%2Cformat%3Dauto%2Fhttps%253A%252F%252Fdev-to-uploads.s3.amazonaws.com%252Fuploads%252Farticles%252Fm18rrjw90un23llw8jcn.jpg&w=1200&q=75)
Structured Concurrency in Practice: CoroutineScope vs StructuredTaskScope [Part 5]
This post series assumes familiarity with Kotlin, Java, and Spring Boot. No AI was used during the writing of this post series. CoroutineScope vs StructuredTaskScope: Which one to choose? Let's summarize what it took to build both solutions: CoroutineScope We had to add 2 libraries val coroutinesVersion = "1.10.2" implementation ( "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion" ) implementation ( "org.jetbrains.kotlinx:kotlinx-coroutines-slf4j:$coroutinesVersion" ) We had to use runBlocking We had to change the dispatcher (we used Dispatchers.IO ) We had to wrap blocking calls in runInterruptible We had to pass MDCContext() to runBlocking StructuredTaskScope No libraries added, just JDK 25 We had to remember to call join We had to build some helpers/wrappers to make it smooth: taskScope instead of StructuredTaskScope.open<Any>.use We had to manually propagate MDC in our wrapper or to explore ScopedValue for this use case When to use CoroutineScope and why? Coroutines
Continue reading on Dev.to
Opens in a new tab



