Is there a way for a function to know if it is being run within a coroutine?
For example I have a send_message() function that tries three times to send a message. Between each try it needs to wait one second. If this function is being called from within a coroutine, I'd like the send_message() function to do a coroutine.yield() as part of its wait-1-second loop. But if it's not within a coroutine, then it should do a POSIX usleep() instead.
Is there a way to do this?