Kotlin Coroutines and Delay
Whenever I suspect that there's a timing conflict causing a problem with rendering and directives, I usually opt for a JavaScript setTimeout
with a delay. The setTimeout
code never makes it to production, but it does help me to understand if my code is the problem or if there's a timing conflict.
In working with Kotlin on Android, I've needed to employ the same technique. Kotlin obviously doesn't have a setTimeout
, but it does have coroutines to achieve approximately the same effect.
To run an async coroutine with delay, you can use the following Kotlin code:
// Create an async coroutine
GlobalScope.launch {
delay(1000)
// Execute code to test functionality
}
The coroutine becomes async and the delay can be whatever amount of milliseconds you'd like!
I love almost every part of being a tech blogger: learning, preaching, bantering, researching. The one part about blogging that I absolutely loathe: dealing with SPAM comments. For the past two years, my blog has registered 8,000+ SPAM comments per day. PER DAY. Bloating my database...
CSS animations aren't just for basic fades or sliding elements anymore -- CSS animations are capable of much more. I've showed you how you can create an exploding logo (applied with JavaScript, but all animation is CSS), an animated Photo Stack, a sweet...
Google Plus provides loads of inspiration for front-end developers, especially when it comes to the CSS and JavaScript wonders they create. Last year I duplicated their incredible PhotoStack effect with both MooTools and pure CSS; this time I'm going to duplicate...
One project I'm currently working on requires jQuery. The project also features a datepicker for requesting a visit to their location. jQuery UI's DatePicker plugin was the natural choice and it does a really nice job. One challenge I encountered was the...