Skip to content

Commit e166a2f

Browse files
authored
Adds http_request_fire_and_forget (#232)
1 parent 28e69fb commit e166a2f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

dmsrc/http.dm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
#define rustg_http_request_blocking(method, url, body, headers, options) RUSTG_CALL(RUST_G, "http_request_blocking")(method, url, body, headers, options)
88
#define rustg_http_request_async(method, url, body, headers, options) RUSTG_CALL(RUST_G, "http_request_async")(method, url, body, headers, options)
99
#define rustg_http_check_request(req_id) RUSTG_CALL(RUST_G, "http_check_request")(req_id)
10+
/// This is basically just `rustg_http_request_async` if you don't care about the response.
11+
/// This will either return "ok" or an error, as this does not create a job.
12+
#define rustg_http_request_fire_and_forget(method, url, body, headers, options) RUSTG_CALL(RUST_G, "http_request_fire_and_forget")(method, url, body, headers, options)

src/http.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ byond_fn!(fn http_request_async(method, url, body, headers, options) {
5454
}))
5555
});
5656

57+
byond_fn!(fn http_request_fire_and_forget(method, url, body, headers, options) {
58+
let req = match construct_request(method, url, body, headers, options) {
59+
Ok(r) => r,
60+
Err(e) => return Some(e.to_string())
61+
};
62+
63+
std::thread::spawn(move || req.req.send_bytes(&req.body));
64+
Some("ok".to_owned())
65+
});
66+
5767
// If the response can be deserialized -> success.
5868
// If the response can't be deserialized -> failure or WIP.
5969
byond_fn!(fn http_check_request(id) {

0 commit comments

Comments
 (0)