Quick answer: Store the id returned by each http_* call. In the Async HTTP event, dispatch on async_load[? "id"] — never assume there’s only one in flight.
A game fires a leaderboard fetch and a profile fetch close together. The Async HTTP event handles whichever finishes first as if it were the other — responses get crossed.
Capture the Request ID
leaderboard_req = http_get("https://api.game.com/leaderboard");
profile_req = http_get("https://api.game.com/profile");
Each call returns a unique id. Store them.
Dispatch in the Async Event
// Async — HTTP event
var rid = async_load[? "id"];
var status = async_load[? "status"];
if (status != 0) exit; // still in progress / error
if (rid == leaderboard_req) {
parse_leaderboard(async_load[? "result"]);
} else if (rid == profile_req) {
parse_profile(async_load[? "result"]);
}
The event fires once per response, in completion order. The id is how you know which response this is.
Map-Based Dispatch
For many concurrent requests, keep a ds_map of id → callback:
pending[? rid] // the handler function for this id
Cleaner than a long if/else chain when you have lots of endpoints.
Handle status Values
status 1 = in progress (ignore), 0 = success, negative = error. Always check before reading result.
Verifying
Fire several requests at once. Each response is routed to the correct handler regardless of completion order. No crossed data.
“The request id is the routing key. Store it per call, dispatch on it in the async event.”
For a clean API layer, build an http_request wrapper that takes a callback and registers it in the pending map automatically.