Skip to content

Commit e3df7c1

Browse files
authored
p3: rework consume-body (#185)
Signed-off-by: Roman Volosatovs <[email protected]>
1 parent ed62056 commit e3df7c1

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

wit-0.3.0-draft/types.wit

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -316,20 +316,12 @@ interface types {
316316
/// future to determine whether the body was received successfully.
317317
/// The future will only resolve after the stream is reported as closed.
318318
///
319-
/// The stream and future returned by this method are children:
320-
/// they should be closed or consumed before the parent `response`
321-
/// is dropped, or its ownership is transferred to another component
322-
/// by e.g. `handler.handle`.
319+
/// This function takes a `res` future as a parameter, which can be used to
320+
/// communicate an error in handling of the request.
323321
///
324-
/// This method may be called multiple times.
325-
///
326-
/// This method will return an error if it is called while either:
327-
/// - a stream or future returned by a previous call to this method is still open
328-
/// - a stream returned by a previous call to this method has reported itself as closed
329-
/// Thus there will always be at most one readable stream open for a given body.
330-
/// Each subsequent stream picks up where the previous one left off,
331-
/// continuing until the entire body has been consumed.
332-
consume-body: func() -> result<tuple<stream<u8>, future<result<option<trailers>, error-code>>>>;
322+
/// Note that function will move the `request`, but references to headers or
323+
/// request options acquired from it previously will remain valid.
324+
consume-body: static func(this: request, res: future<result<_, error-code>>) -> tuple<stream<u8>, future<result<option<trailers>, error-code>>>;
333325
}
334326

335327
/// Parameters for making an HTTP Request. Each of these parameters is
@@ -417,19 +409,11 @@ interface types {
417409
/// future to determine whether the body was received successfully.
418410
/// The future will only resolve after the stream is reported as closed.
419411
///
420-
/// The stream and future returned by this method are children:
421-
/// they should be closed or consumed before the parent `response`
422-
/// is dropped, or its ownership is transferred to another component
423-
/// by e.g. `handler.handle`.
424-
///
425-
/// This method may be called multiple times.
412+
/// This function takes a `res` future as a parameter, which can be used to
413+
/// communicate an error in handling of the response.
426414
///
427-
/// This method will return an error if it is called while either:
428-
/// - a stream or future returned by a previous call to this method is still open
429-
/// - a stream returned by a previous call to this method has reported itself as closed
430-
/// Thus there will always be at most one readable stream open for a given body.
431-
/// Each subsequent stream picks up where the previous one left off,
432-
/// continuing until the entire body has been consumed.
433-
consume-body: func() -> result<tuple<stream<u8>, future<result<option<trailers>, error-code>>>>;
415+
/// Note that function will move the `response`, but references to headers
416+
/// acquired from it previously will remain valid.
417+
consume-body: static func(this: response, res: future<result<_, error-code>>) -> tuple<stream<u8>, future<result<option<trailers>, error-code>>>;
434418
}
435419
}

0 commit comments

Comments
 (0)