Skip to content

Commit

Permalink
dynamic reevaluation of function
Browse files Browse the repository at this point in the history
Call `Core._applu_latest` to support `open` mode in `APIResponder` on Julia 0.6.

We can call `Compat.invoke_latest` instead after JuliaLang/julia#22646 is merged and assimilated in Compat.jl suitably.
  • Loading branch information
tanmaykm committed Jul 24, 2017
1 parent 457dcd1 commit d5cd8b4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/APIResponder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,23 @@ function get_resp(api::Nullable{APISpec}, status::Symbol, resp=nothing)
end
end

# Note: needs to be changed when https://github.com/JuliaLang/julia/pull/22646 is merged
function dynamic_invoke(conn::APIResponder, f, args...; kwargs...)
if conn.open && isdefined(Core, :_apply_latest)
inner() = f(args...; kwargs...)
Core._apply_latest(inner)
else
f(args...; kwargs...)
end
end

"""call the actual API method, and send the return value back as response"""
function call_api(api::APISpec, conn::APIResponder, args, data::Dict{Symbol,Any})
try
if !applicable(api.fn, args...)
narrow_args!(args)
end
result = api.fn(args...; data...)
result = dynamic_invoke(conn, api.fn, args...; data...)
respond(conn, Nullable(api), :success, result)
catch ex
err("api_exception: $ex")
Expand Down

0 comments on commit d5cd8b4

Please sign in to comment.