web_wt_sys/webtransport/web_transport_writer.rs
1//! [`WebTransportWriter`]
2//!
3//! <https://w3c.github.io/webtransport/#web-transport-writer-interface>
4
5use js_sys::Object;
6use wasm_bindgen::prelude::*;
7use web_sys::{DomException, WritableStreamDefaultWriter};
8
9#[wasm_bindgen]
10extern "C" {
11 ///The `WebTransportWriter` interface.
12 ///
13 /// <https://w3c.github.io/webtransport/#webtransportwriter>
14 #[wasm_bindgen(extends = WritableStreamDefaultWriter, extends = Object)]
15 #[derive(Debug, Clone, PartialEq, Eq)]
16 pub type WebTransportWriter;
17
18 /// ```webidl
19 /// Promise<undefined> atomicWrite(optional any chunk);
20 /// ```
21 ///
22 /// <https://w3c.github.io/webtransport/#dom-webtransportwriter-atomicwrite>
23 ///
24 /// The atomicWrite method will reject if the chunk given to it could
25 /// not be sent in its entirety within the flow control window that is
26 /// current at the time of sending.
27 /// This behavior is designed to satisfy niche transactional applications
28 /// sensitive to flow control deadlocks ([RFC9308] Section 4.4).
29 ///
30 /// NOTE: atomicWrite can still reject after sending some data.
31 /// Though it provides atomicity with respect to flow control,
32 /// other errors may occur.
33 /// atomicWrite does not prevent data from being split between packets or
34 /// being interleaved with other data.
35 /// Only the sender learns if atomicWrite fails due to lack of available
36 /// flow control credit.
37 ///
38 /// NOTE: Atomic writes can still block if queued behind non-atomic writes.
39 /// If the atomic write is rejected, everything queued behind it at that
40 /// moment will be rejected as well.
41 /// Any non-atomic writes rejected in this way will error the stream.
42 /// Applications are therefore encouraged to always await atomic writes.
43 #[wasm_bindgen(method, js_name = atomicWrite, catch)]
44 pub async fn atomic_write(this: &WebTransportWriter) -> Result<(), DomException>;
45
46 /// ```webidl
47 /// Promise<undefined> atomicWrite(optional any chunk);
48 /// ```
49 ///
50 /// <https://w3c.github.io/webtransport/#dom-webtransportwriter-atomicwrite>
51 ///
52 /// The atomicWrite method will reject if the chunk given to it could
53 /// not be sent in its entirety within the flow control window that is
54 /// current at the time of sending.
55 /// This behavior is designed to satisfy niche transactional applications
56 /// sensitive to flow control deadlocks ([RFC9308] Section 4.4).
57 ///
58 /// NOTE: atomicWrite can still reject after sending some data.
59 /// Though it provides atomicity with respect to flow control,
60 /// other errors may occur.
61 /// atomicWrite does not prevent data from being split between packets or
62 /// being interleaved with other data.
63 /// Only the sender learns if atomicWrite fails due to lack of available
64 /// flow control credit.
65 ///
66 /// NOTE: Atomic writes can still block if queued behind non-atomic writes.
67 /// If the atomic write is rejected, everything queued behind it at that
68 /// moment will be rejected as well.
69 /// Any non-atomic writes rejected in this way will error the stream.
70 /// Applications are therefore encouraged to always await atomic writes.
71 #[wasm_bindgen(method, js_name = atomicWrite, catch)]
72 pub async fn atomic_write_with_chunk(
73 this: &WebTransportWriter,
74 chunk: &JsValue,
75 ) -> Result<(), DomException>;
76}