In general, you want to make your code as asynchronous-friendly as possible, e.g. by never calling sleep, having a single main loop and so on.

Sometimes refactoring a codebase with this in mind isn’t feasible, so there are a couple of alternatives (each with downsides). Asyncify is covered here.

Asyncify is experimental, and not recommended. See https://kripken.github.io/emscripten-site/docs/porting/emterpreter.html for a more recent option with similar functionality, that is currently supported.

ASYNCIFY allows you to use some asynchronous function in C, through several transformation of LLVM IR.