But the code doesn’t print anything, looks like the “trap_exit” not working. Here is the document of Task.await:
A timeout, in milliseconds or :infinity , can be given with a default value of 5000 . If the timeout is exceeded, then the caller process will exit. If the task process is linked to the caller process which is the case when a task is started with async , then the task process will also exit. If the task process is trapping exits or not linked to the caller process, then it will continue to run.
How could I detect the timeout of Task.await and print a proper error log? Thanks.
Ah I apologize I thought both would work. I’m not sure why that one doesn’t print anything without digging deeper. But probably one of the smart people around here already knows and will speak up :).
It looks like Task.async sets up a monitor so you might receive a down message first. I think you still need the exit trapping so the spawn process doesn’t die before receiving the down message.