Hi there,
I would like to write a macro which just waits until a next time, if I run it on my own in a repl, it works, but if I put it into a macro, it fails with
ERROR: syntax: invalid let syntax around task.jl:453
here the macro
using Dates
macro waituntil(nexttime_from_now, sleeptime_from_diff)
quote
nexttime = $nexttime_from_now()
@sync @async begin
diff = nexttime - Dates.now()
while diff > Dates.Millisecond(0)
sleep($sleeptime_from_diff(diff))
diff = nexttime - Dates.now()
end
end
end
end
julia> nexttime_from_now() = ceil(Dates.now(), Dates.Second(30))
nexttime_from_now (generic function with 1 method)
julia> sleeptime_from_diff(diff) = max(div(diff,2), Dates.Millisecond(2000))
sleeptime_from_diff (generic function with 1 method)
julia> @waituntil(nexttime_from_now, sleeptime_from_diff)
ERROR: syntax: invalid let syntax around task.jl:453
Stacktrace:
[1] top-level scope
@ REPL[25]:1
doing it without a macro works…
begin
nexttime = nexttime_from_now()
@sync @async begin
diff = nexttime - Dates.now()
while diff > Dates.Millisecond(0)
sleep(sleeptime_from_diff(diff))
diff = nexttime - Dates.now()
end
end
end
any help on how to get this into a macro is highly appreciated
running on Julia 1.8.1
EDIT: inspecting the macros it seems to be that @sync
is generating invalid let syntax like let Main.:(var"##sync#48") = Base.Channel(Base.Inf)
when used within a macro. Is this a bug?