Use case in case it matters is to have non-flaky unit tests without having to over-abstract things (which is why I’d prefer to not have some boolean iscallbackdone inside the callback).
function testtimer() ss = "" tt = Timer(1) do t ss *= "aa" end wait(tt) ss *= "bb" sleep(1.1) return ss end julia> testtimer() # Want "aabb" "bbaa"
yield() or similar between timer start and
wait(tt) makes the function produce the desired output, but I doubt it will be robust enough to pass on free CI.
This works, but I want to have a reference to the timer so I can stop (close) it:
function testtask() ss = "" tt = @async begin wait(Timer(1) do t ss *= "aa" end) end wait(tt) ss *= "bb" sleep(1.1) return ss end julia> testtask() "aabb"