summaryrefslogtreecommitdiff
path: root/ext/http/http_next.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-11-08 18:46:11 +0530
committerGitHub <noreply@github.com>2024-11-08 18:46:11 +0530
commitb482a50299ae4f636a186038460e54af65e2b627 (patch)
tree0d9cb0f2348391b438efa133afd391b189ec0e30 /ext/http/http_next.rs
parent637b1d5508293ed02bef2f317b30bb7c1f0cbc71 (diff)
feat(ext/http): abort event when request is cancelled (#26781)
```js Deno.serve(async (req) => { const { promise, resolve } = Promise.withResolvers<void>(); req.signal.addEventListener("abort", () => { resolve(); }); await promise; return new Response("Ok"); }); ```
Diffstat (limited to 'ext/http/http_next.rs')
-rw-r--r--ext/http/http_next.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/ext/http/http_next.rs b/ext/http/http_next.rs
index 326478fe7..c55e86835 100644
--- a/ext/http/http_next.rs
+++ b/ext/http/http_next.rs
@@ -708,6 +708,19 @@ pub fn op_http_get_request_cancelled(external: *const c_void) -> bool {
http.cancelled()
}
+#[op2(async)]
+pub async fn op_http_request_on_cancel(external: *const c_void) {
+ let http =
+ // SAFETY: op is called with external.
+ unsafe { clone_external!(external, "op_http_request_on_cancel") };
+ let (tx, rx) = tokio::sync::oneshot::channel();
+
+ http.on_cancel(tx);
+ drop(http);
+
+ rx.await.ok();
+}
+
/// Returned promise resolves when body streaming finishes.
/// Call [`op_http_close_after_finish`] when done with the external.
#[op2(async)]