Possible to check if non-async function is called in an async context?

I am writing some async code, but I also have sync code and they both do file system calls.

I am using tokio.

I want to "make sure" (at least in debug mode) that file system calls are either done in an async fashion (using tokio's APIs), or in spawn_blocking if they are in an async context, but most importantly that if they are not called in an async context, they should not be in an non-blocking (spawn) task.

EDIT That last sentence may need some explaining: so if someone calls that function, I want it to assert that it is not called in async mode, or at least that it is called from spawn_blocking.

Are there APIs in tokio to inspect / assert on these things?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.