Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 3 additions & 3 deletions test/srvr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const SRVR_ADDR = "tcp://127.0.0.1:9999"
const JSON_RESP_HDRS = Dict{String,String}("Content-Type" => "application/json; charset=utf-8")
const BINARY_RESP_HDRS = Dict{String,String}("Content-Type" => "application/octet-stream")

function run_srvr(fmt, tport, async=false)
function run_srvr(fmt, tport, async=false, open=false)
Logging.configure(level=INFO, filename="apisrvr_test.log")
Logging.info("queue is at $SRVR_ADDR")

api = APIResponder(tport, fmt)
api = APIResponder(tport, fmt, nothing, open)
Logging.info("responding with: $api")

register(api, testfn1; resp_json=true, resp_headers=JSON_RESP_HDRS)
Expand All @@ -40,7 +40,7 @@ function test_preproc(req::Request, res::Response)
end

function run_httprpcsrvr(fmt, tport, async=false)
run_srvr(fmt, tport, true)
run_srvr(fmt, tport, true, true)
apiclnt = APIInvoker(ZMQTransport(SRVR_ADDR, REQ, false), fmt)
if async
@async run_http(apiclnt, 8888, test_preproc)
Expand Down