Volatile keyword tells the compiler that a variable might be modified asynchronously
by concurrently running
thre…n creates the Singleton. Yet, this is not enough and the instance also needs to be marked
volatile. Volatile keyword tells the compiler that a variable might be modified asynchronously by concurrently running threads.
Warning: A big difference between
async is how they handle exceptions.
async expects that you will eventually call
await to get a result (or exception) so it won’t throw exceptions by default. That means if you use
async to start a new coroutine it will silently drop exceptions.
f supervisorSc…coroutine started by
coroutineScope throws an exception,
coroutineScope can throw it to the caller. Since we’re using
coroutineScope instead of
supervisorScope, it would also immediately cancel all other children when the exception is thrown.