- When you receive the message you want to delay processing,
send_after
another message to “yourself” that contains enough information to do the actual work - and do it when that message arrives. - Use
:no_reply
in yourhandle_*
result (i.e. after thesend_after
has been processed). - You can use
GenServer.reply/2
to reply to the caller at that later time.
Building Non Blocking Erlang apps discusses the approach in more detail - the code is in Erlang but it’s similar enough.