Skip to content

Commit 40aa8d8

Browse files
committed
Simplify implementation of mt_async for Julia >= v1.4
1 parent 138a55c commit 40aa8d8

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/onthreads.jl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,23 @@ Equivalent to `Base.@async` on Julia <= v1.2, equivalent to
207207
`Base.Threads.@spawn` on Julia >= v1.3.
208208
"""
209209
macro mt_async(expr)
210-
# Code taken from Base.@async and Base.Threads.@spawn:
211-
thunk = esc(:(()->($expr)))
212-
var = esc(Base.sync_varname)
213-
quote
214-
local task = Task($thunk)
215-
@static if VERSION >= v"1.3.0-alpha.0"
216-
task.sticky = false
217-
end
218-
if $(Expr(:isdefined, var))
219-
push!($var, task)
210+
@static if VERSION >= v"1.4.0"
211+
:(Base.Threads.@spawn $(esc(expr)))
212+
else
213+
# Code taken from Base.@async and Base.Threads.@spawn:
214+
thunk = esc(:(()->($expr)))
215+
var = esc(Base.sync_varname)
216+
quote
217+
local task = Task($thunk)
218+
@static if VERSION >= v"1.3.0-alpha.0"
219+
task.sticky = false
220+
end
221+
if $(Expr(:isdefined, var))
222+
push!($var, task)
223+
end
224+
schedule(task)
225+
task
220226
end
221-
schedule(task)
222-
task
223227
end
224228
end
225229
export @mt_async

0 commit comments

Comments
 (0)