I am trying to execute a function on a different thread after a specified delay. I could use Timer
, but I need to fetch the result. As shown below, my solution was to use sleep. I was wondering if this is there are better approaches.
import Base.Threads: @spawn
function run_at(f, delay)
sleep(delay)
return f()
end
f() = sum(rand(10000))
t1 = @spawn run_at(f, 3)
fetch(t1)