Asynchronous protocol

Pieces of little code. Is there a better way to do this, generally
speaking?