Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@one_by_one doesn't work inside a if-block #118

Open
Moelf opened this issue Sep 18, 2024 · 2 comments
Open

@one_by_one doesn't work inside a if-block #118

Moelf opened this issue Sep 18, 2024 · 2 comments
Labels
bug Something isn't working enhancement New feature or request macro-api

Comments

@Moelf
Copy link

Moelf commented Sep 18, 2024

julia> @tasks for i in 1:10
           if true
               @one_by_one begin
                   println(i)
                   sleep(0.1)
               end
           end
       end
ERROR: LoadError: The @one_by_one macro may only be used inside of a @tasks block.
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] var"@one_by_one"(__source__::LineNumberNode, __module__::Module, args::Vararg{Any})
   @ OhMyThreads ~/.julia/packages/OhMyThreads/20X0i/src/macros.jl:207
in expression starting at REPL[2]:3

Currently the @tasks macro needs to see @one_by_one directly, but logically speaking this is not necessary

@carstenbauer
Copy link
Member

We need to recursively look for our special macros. Probably using MacroTools is easiest.

@carstenbauer
Copy link
Member

carstenbauer commented Sep 18, 2024

We only cared about “top-level” (relative to @tasks) because we started with @set and @local and those only make sense there. Supporting @one_by_one in (potentially nested) if(s) is harder than I thought. It doesn’t fit into the scheme we currently use to find and replace those macros.

As a workaround you can use:

julia> @tasks for i in 1:10
           if true
               lock(lck) do
                   println(i)
                   sleep(0.1)
               end
           end
       end
3
10
7
9
5
6
4
8
1
2

@carstenbauer carstenbauer added enhancement New feature or request bug Something isn't working macro-api labels Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request macro-api
Projects
None yet
Development

No branches or pull requests

2 participants