Skip to content

Instantly share code, notes, and snippets.

@anandwana001
Created October 4, 2025 03:06
Show Gist options
  • Select an option

  • Save anandwana001/55c0b3d33670af980e18654af7fa5e54 to your computer and use it in GitHub Desktop.

Select an option

Save anandwana001/55c0b3d33670af980e18654af7fa5e54 to your computer and use it in GitHub Desktop.
class EventProcessor {
suspend fun processEvent(event: String) = withContext(Dispatchers.Unconfined) {
// Use unconfined for immediate processing without thread switching overhead
// Only suitable when no specific thread is required
println("Processing $event immediately on ${Thread.currentThread().name}")
}
}
fun main() = runBlocking {
val processor = EventProcessor()
launch(Dispatchers.Default) {
processor.processEvent("Event1")
}
launch(Dispatchers.IO) {
processor.processEvent("Event2")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment