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, Promise};
6use wasm_bindgen::prelude::*;
7use web_sys::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)]
44 pub fn atomic_write(this: &WebTransportWriter) -> Promise;
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)]
72 pub fn atomic_write_with_chunk(this: &WebTransportWriter, chunk: &JsValue) -> Promise;
73
74 /// ```webidl
75 /// undefined commit();
76 /// ```
77 ///
78 /// <https://w3c.github.io/webtransport/#dom-webtransportwriter-commit>
79 ///
80 /// Updates the `[[CommittedOffset]]` of a stream to match the number of
81 /// bytes written to that stream (`[[BytesWritten]]`).
82 /// This ensures that those bytes will be delivered to a peer reliably,
83 /// even after writing is aborted, causing the stream to abort sending.
84 /// This uses the mechanism described in [RELIABLE-RESET].
85 ///
86 /// NOTE: This does not guarantee delivery in the event that a connection
87 /// fails, only when a stream has aborted sending.
88 #[wasm_bindgen(method)]
89 pub fn commit(this: &WebTransportWriter);
90}