Resetting Counter in a While loop

It seems to work for me.

julia> a = ["a", "b"]
2-element Vector{String}:
 "a"
 "b"

julia> function test2(a)
           cont = Ref(true)
           @async for x in Iterators.cycle(a)
               cont[] || break
               println(x)
               sleep(5)
           end
           return cont
       end
test2 (generic function with 1 method)

julia> c = test2(a);
a

julia> b
a
b
a
julia>

julia> c[]=false
false
# no more output
1 Like