Created
October 4, 2025 03:06
-
-
Save anandwana001/55c0b3d33670af980e18654af7fa5e54 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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