So, I attempted to replace the custom lock with Mutex. However, since Mutex's withLock method’s body closure has a sending return type, we are, with the current sate of RBI, quite limited what we can do in such cases. I think we need to improve flow analysis first or even introduce call-once closures before this would work.