Can a function know if it works inside a coroutine?

Is there a way for a function to know if it runs inside a coroutine?

For example, I have a send_message () function that tries to send a message three times. Between each attempt you need to wait one second. If this function is called from within a coroutine, I would like the send_message () function to execute the coroutine.yield () command as part of a 1 second wait loop. But if it is not inside the coroutine, then it should do POSIX usleep () instead.

Is there any way to do this?

+3
source share
1 answer
+5

Source: https://habr.com/ru/post/1761440/


All Articles