Let's start with something simple.
julia> using Rocket
julia> ints = iterable(1:10)
IterableObservable(Int64, UnitRange{Int64}, AsapScheduler)
julia> subscribe!(ints, logger("n"))
[n] Data: 1
[n] Data: 2
[n] Data: 3
[n] Data: 4
[n] Data: 5
[n] Data: 6
[n] Data: 7
[n] Data: 8
[n] Data: 9
[n] Data: 10
[n] Completed
VoidTeardown()
How could I hook the animated progress bar from ProgressLogging.jl into this iteration? (The logger(n)
is just there for demo purposes. Feel free to get rid of it if you want.)
PS: I think you have to setup TerminalLoggers.jl to get nice animations in the REPL. Do something like this first.
using TerminalLoggers
global_logger(TerminalLogger(right_justify=80))
using ProgressLogging
take!
was the key.ProgressLogging.progress()
and not leave until Rocket.jl was done iterating.Channel
and I did a take!(ch)
on it which blocks the main thread until it can take something.on_complete
puts something in the channel.function start_iteration(observable)
# Let a LambdaActor subscribe to candle_subject for progress logging.
i = 1
len = length(observable.iterator)
ch = Channel(1)
ProgressLogging.progress() do id
# setup progress
on_next = function(n::Int)
println("i:$(i) len:$(len) ratio=$(i/len)")
@info "running" _id=id progress=(i/len)
i += 1
sleep(0.1)
end
on_complete() = put!(ch, 1)
subscribe!(observable, lambda(;on_next, on_complete))
# block until our on_complete fires
take!(ch)
end
end
It's used like this:
julia> start_iteration(ints)
G Gundam has marked this topic as resolved.
Last updated: Dec 28 2024 at 04:38 UTC