Sat, 28 Dec 2019 11:12:41 +0200
@backgroundif
src/Util.jl | file | annotate | diff | comparison | revisions |
--- a/src/Util.jl Sat Dec 28 10:14:02 2019 +0200 +++ b/src/Util.jl Sat Dec 28 11:12:41 2019 +0200 @@ -25,7 +25,8 @@ curry, ⬿, @threadsif, - @background + @background, + @backgroundif ########## @@ -35,9 +36,9 @@ macro threadsif(threads, loop) return esc(:(if $threads Threads.@threads $loop - else + else $loop - end)) + end)) end macro background(bgtask, fgtask) @@ -46,6 +47,15 @@ wait(t)) end +macro backgroundif(threads, bgtask, fgtask) + return :(if $(esc(threads)) + @background $(esc(bgtask)) $(esc(fgtask)) + else + $(esc(bgtask)) + $(esc(fgtask)) + end) +end + ######################## # Functional programming #########################