How I Fell in Kotlin’s RunBlocking Deadlock Trap, and How You Can Avoid It

<p>It&rsquo;s a super easy way to start new coroutines. Calling a suspending function like&nbsp;<code>delay</code>&nbsp;from a plain old function would normally give you an angry red compilation error. But wrap it with&nbsp;<code>runBlocking</code>, and suddenly you&rsquo;re free not only to call all the suspending functions you like, but also to use coroutine builders like&nbsp;<code>launch</code>&nbsp;and&nbsp;<code>async</code>.</p> <p>Using&nbsp;<code>runBlocking</code>&nbsp;in the main function like this is no problem. But when was the last time you actually added code to the main entry point of a real production system? When you&rsquo;re working with coroutines, you&rsquo;re more likely to be deep within your app&rsquo;s code, and that&rsquo;s where things get more complicated.</p> <p><a href="https://betterprogramming.pub/how-i-fell-in-kotlins-runblocking-deadlock-trap-and-how-you-can-avoid-it-db9e7c4909f1"><strong>Click Here</strong></a></p>
Tags: Deadlock trap