Skip to content

Commit 60c4d31

Browse files
committed
feat(0.3): rework stream error handling
Signed-off-by: Roman Volosatovs <[email protected]>
1 parent 8eb7f8a commit 60c4d31

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

wit-0.3.0-draft/types.wit

+11-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/// Requests and Responses, as well as their headers, trailers, and bodies.
33
interface types {
44
use wasi:clocks/monotonic-clock@0.2.3.{duration};
5-
use wasi:io/error@0.2.3.{error};
65

76
/// This type corresponds to HTTP standard Methods.
87
variant method {
@@ -92,18 +91,6 @@ interface types {
9291
field-size: option<u32>
9392
}
9493

95-
/// Attempts to extract a http-related `error-code` from the stream `error`
96-
/// provided.
97-
///
98-
/// Stream operations may fail with a stream `error` with more information
99-
/// about the operation that failed. This `error` can be passed to this
100-
/// function to see if there's http-related information about the error to
101-
/// return.
102-
///
103-
/// Note that this function is fallible because not all stream errors are
104-
/// http-related errors.
105-
http-error-code: func(err: borrow<error>) -> option<error-code>;
106-
10794
/// This type enumerates the different kinds of errors that may occur when
10895
/// setting or appending to a `fields` resource.
10996
variant header-error {
@@ -254,16 +241,24 @@ interface types {
254241
resource body {
255242

256243
/// Construct a new `body` with the specified stream and trailers.
257-
constructor(
244+
/// This function returns a future, which will resolve
245+
/// to an error code if transmitting stream data or trailers fails.
246+
/// The returned future resolves to success once body stream and trailers
247+
/// are fully transmitted.
248+
new: static func(
258249
%stream: stream<u8>,
259250
trailers: option<future<trailers>>
260-
);
251+
) -> tuple<body, future<result<_, error-code>>>;
261252

262253
/// Returns the contents of the body, as a stream of bytes.
263254
///
264255
/// This function may be called multiple times as long as any `stream`s
265256
/// returned by previous calls have been dropped first.
266-
%stream: func() -> result<stream<u8>>;
257+
///
258+
/// On success, this function returns a stream and a future, which will resolve
259+
/// to an error code if receiving data from stream fails.
260+
/// The returned future resolves to success if body is closed.
261+
%stream: func() -> result<tuple<stream<u8>>, future<result<_, error-code>>>;
267262

268263
/// Takes ownership of `body`, and returns a `trailers`. This function will
269264
/// trap if a `stream` child is still alive.

0 commit comments

Comments
 (0)