How to interrupt fun(a,b) in a for loop after 10 seconds?

The problem of terminating an async task has been discussed over here:

The conclusion seems to have been

task = @async some_long_running_function()
sleep(5) # give it some time to run
schedule(task, InterruptException(), error=true) # send an interrupt exception