Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperancinha committed Mar 21, 2024
2 parents 478af61 + 283338c commit 60cdfea
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ object Main {
SimpleConcurrency.main()
GlobalScopeCoroutine.main()
UnconfinedCats.main()
MainDispatcherLauncher.main()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.jesperancinha.ktd

import kotlinx.coroutines.*
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.time.LocalDateTime

class MainDispatcherLauncher {

companion object {
val logger: Logger = LoggerFactory.getLogger(MainDispatcherLauncher::class.java)

@JvmStatic
fun main(args: Array<String> = emptyArray()) = runBlocking {
runMainCoroutinesTest()
}

private suspend fun runMainCoroutinesTest() {
try {
val job = CoroutineScope(Dispatchers.Main).launch {
launch {
delay(100)
logger.info("This is cat @ ${LocalDateTime.now()}")
}
launch {
logger.info("This is mouse @ ${LocalDateTime.now()}")
}
logger.info("This is master @ ${LocalDateTime.now()}")
}
job.join()
} catch (ex: IllegalStateException) {
logger.info("Error!", ex)
}
}

}
}

0 comments on commit 60cdfea

Please sign in to comment.