@@ -1798,18 +1798,31 @@ An analogous relationship exists among `readable-future-end<T?>`,
1798
1798
where ` stream-result ` is defined in WIT as:
1799
1799
``` wit
1800
1800
record stream-result {
1801
- progress: u32,
1802
- result: copy-result
1801
+ /// The number of elements read/written.
1802
+ progress: u32,
1803
+
1804
+ /// The status of the read/write operation.
1805
+ result: copy-result
1803
1806
}
1804
1807
1805
1808
enum copy-result {
1806
- // The read/write completed successfully and is ready for more.
1809
+ /// The read/write completed successfully.
1810
+ ///
1811
+ /// The stream remains open for new reads/writes.
1807
1812
completed,
1808
1813
1809
- // The other end was dropped and so this end must now be dropped.
1814
+ /// The other end was dropped and so this end must now be dropped.
1815
+ ///
1816
+ /// For `stream.read`, this means that the end of the stream was reached.
1817
+ ///
1818
+ /// For `stream.write`, this means that the consumer has no need for further
1819
+ /// data from this stream. This doesn't signify an error; it just instructs
1820
+ /// the producer to stop sending data.
1810
1821
dropped,
1811
1822
1812
- // The read/write was cancelled by stream.cancel-{read,write}; future reads/writes are possible.
1823
+ /// The read/write was cancelled by `stream.cancel-{read,write}`.
1824
+ ///
1825
+ /// The stream remains open for new reads/writes.
1813
1826
cancelled
1814
1827
}
1815
1828
```
@@ -1824,14 +1837,17 @@ many `T` elements were read or written from the given buffer before the
1824
1837
` copy-result ` was reached. For example, a return value of `{progress: 4,
1825
1838
result: dropped}` from a ` stream<u32 >.read` means that 32 bytes were copied
1826
1839
into the given buffer before the writer end dropped the stream. The ` cancelled `
1827
- case can only arise as the result of a call to ` stream.cancel-{read,write} `
1828
- and is included in ` copy-result ` because it is reused below.
1840
+ case can only arise as the result of a call to ` stream.cancel-{read,write} ` .
1829
1841
1830
1842
If the return value is ` none ` , then the operation blocked and the caller needs
1831
1843
to [ wait] ( Async.md#waiting ) for progress (via ` waitable-set.{wait,poll} ` or, if
1832
1844
using a ` callback ` , by returning to the event loop) which will asynchronously
1833
1845
produce an ` event ` containing a ` stream-result ` .
1834
1846
1847
+ If ` stream.{read,write} ` return ` dropped ` (synchronously or asynchronously),
1848
+ any subsequent operation on the stream other than ` stream.drop-{readable,writable} `
1849
+ traps.
1850
+
1835
1851
In the Canonical ABI, the ` {readable,writable}-stream-end ` is passed as an
1836
1852
` i32 ` index into the component instance's table followed by a pair of ` i32 ` s
1837
1853
describing the linear memory offset and size-in-elements of the
@@ -1854,20 +1870,24 @@ bit-packed into a single `i32` where:
1854
1870
where ` future-{read,write}-result ` are defined in WIT as:
1855
1871
``` wit
1856
1872
enum future-read-result {
1857
- // The read completed and this readable end must now be dropped.
1873
+ /// The read completed and this readable end must now be dropped.
1858
1874
completed,
1859
1875
1860
- // The read was cancelled by future.cancel-read; future reads are possible.
1876
+ /// The read was cancelled by `future.cancel-read`.
1877
+ ///
1878
+ /// The future remains open for a new `future.read`.
1861
1879
cancelled
1862
1880
}
1863
1881
enum future-write-result {
1864
- // The write completed successfully and this writable end must now be dropped.
1882
+ /// The write completed successfully and this writable end must now be dropped.
1865
1883
completed,
1866
1884
1867
- // The readable end was dropped and so the writable end must now be dropped.
1885
+ /// The readable end was dropped and so the writable end must now be dropped.
1868
1886
dropped,
1869
1887
1870
- // The write was cancelled by future.cancel-write; future writes are possible.
1888
+ /// The write was cancelled by `future.cancel-write`.
1889
+ ///
1890
+ /// The future remains open for a new `future.write`.
1871
1891
cancelled
1872
1892
}
1873
1893
```
@@ -1878,17 +1898,17 @@ to drop their end before writing a value). `future-write-result` is the same as
1878
1898
that the reader signalled loss of interest by dropping their end).
1879
1899
1880
1900
The ` future.{read,write} ` built-ins takes the [ readable or writable end] of a
1881
- future as the first parameter and, if ` T ` is present, a length-1 buffer that
1882
- can be used to write or read a single ` T ` value.
1901
+ future as the first parameter and, if ` T ` is present, a single-element buffer
1902
+ that can be used to write or read a single ` T ` value.
1883
1903
1884
1904
If the return value is ` none ` , then the call blocked and the caller needs
1885
1905
to [ wait] ( Async.md#waiting ) for progress (via ` waitable-set.{wait,poll} ` or, if
1886
1906
using a ` callback ` , by returning to the event loop) which will asynchronously
1887
1907
produce an ` event ` containing a ` future-{read,write}-result ` .
1888
1908
1889
1909
If ` future.{read,write} ` return ` completed ` or ` dropped ` (synchronously or
1890
- asynchronously), the only valid next operation is
1891
- ` future.drop-{readable,writable} ` .
1910
+ asynchronously), any subsequent operation on the future other than
1911
+ ` future.drop-{readable,writable} ` traps .
1892
1912
1893
1913
A component * may* call ` future.drop-readable ` * before* successfully reading a
1894
1914
value to indicate a loss of interest. ` future.drop-writable ` will trap if
0 commit comments