Bukdu, How to use a Timer

When run >julia server.jl The Timer is not triggered. Is this caused by Bukdu? Thanks!

#server.jl
using Bukdu
using HTTP

const g_temp_data = Ref{String}
function do_work(t)
    g_temp_data[] ="Hello the word"
    println("call do_work()")
end
timer = Timer(do_work, 1; interval=20)

struct RouteController <: ApplicationController
    conn::Conn
end

function index(c::RouteController)
    output = g_temp_data[]
    render(JSON, output)
end
routes() do
    get("/", RouteController, index)
end

Bukdu.start(8885, host="0.0.0.0", enable_remote_ip=true)
Base.JLOptions().isinteractive == 0 && wait()

It looks like you never use (wait for) the timer, you are just creating it.

1 Like

you should make Ref{String}()

julia> g_temp_data = Ref{String}
Ref{String}

julia> g_temp_data[] ="Hello the word"
ERROR: MethodError: no method matching setindex!(::Type{Ref{String}}, ::String)
Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

julia> g_temp_data = Ref{String}()
Base.RefValue{String}(#undef)

julia> g_temp_data[] ="Hello the word"
"Hello the word"

and you have a question that related with Bukdu.jl, please open an issue at https://github.com/wookay/Bukdu.jl/issues

1 Like

Thank you so much! It works by adding wait(timer)