Suspend coroutine until condition is true
I have a use case where I need to connect and disconnect from a class that acts as a service. Actions can be performed on the service only when the service is connected. Clients are notified when the service connects or disconnects by a callback: class Service { constructor(callback: ConnectionCallback) { ... } fun connect() { // Call callback.onConnected() some time after this method returns. } fun disconnect() { // Call callback.onConnectionSuspended() some time after this method returns. } fun isConnected(): Boolean { ... } fun performAction(actionName: String, callback: ActionCallback) { /