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!
Sooner or later you'll run across a regular expression. With their cryptic syntax, confusing documentation and massive learning curve, most developers settle for copying and pasting them from StackOverflow and hoping they work. But what if you could decode regular expressions and harness their power? In...
I remember the early days of JavaScript where you needed a simple function for just about everything because the browser vendors implemented features differently, and not just edge features, basic features, like addEventListener
and attachEvent
. Times have changed but there are still a few functions each developer should...
WordPress has a nice little effect on the Admin Dashboard where it shows and hides the comment control links when you mouseover and mouseout of the record's container. Here's how to achieve that effect using MooTools or jQuery.
The XHTML
Notice that we place the links into...
One of the little known JavaScript events is the image onError event. This event is triggered when an image 404's out because it doesn't exist. Broken images can make your website look unprofessional and it's important to fix broken images as soon as possible.