Skip to content

Commit 68d438a

Browse files
polish
Signed-off-by: Adrian Cole <[email protected]>
1 parent d13ec52 commit 68d438a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

examples/log_once.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
;; ctxNext := handleRequest()
3636
(local.set $ctx_next (call $handle_request))
3737

38-
;; isError := awaitResponse(ctxNext())
38+
;; isError := awaitResponse(ctxNext)
3939
(local.set $is_error (call $await_response (local.get $ctx_next)))
4040

41-
;; expected_count = uint32(result >> 32)
41+
;; ctx = uint32(ctxNext >> 32)
4242
(local.set $ctx
4343
(i32.wrap_i64 (i64.shr_u (local.get $ctx_next) (i64.const 32))))
4444

internal/test/testdata/e2e/await_response.wat

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
(module $await_response
22

3+
(; begin adapter logic
4+
5+
Below is generic and can convert any normal handler to a single synchronous
6+
call, provided $handle_request and $handle_response are not exported. ;)
7+
8+
;; import $await_response, which blocks until the response is ready.
39
(import "http_handler" "await_response" (func $await_response
410
(param $ctx_next i64)
511
(result (; is_error ;) i32)))
612

713
;; define a start function that performs a request-response without exports.
14+
;; note: this logic is generic and can convert any exported $handle_request/
15+
;; $handle_response pair to a synchronous call without exports.
816
(func $start
917
(local $ctx_next i64)
1018
(local $is_error i32)
@@ -13,16 +21,18 @@
1321
;; ctxNext := handleRequest()
1422
(local.set $ctx_next (call $handle_request))
1523

16-
;; isError := awaitResponse(ctxNext())
24+
;; isError := awaitResponse(ctxNext)
1725
(local.set $is_error (call $await_response (local.get $ctx_next)))
1826

19-
;; expected_count = uint32(result >> 32)
27+
;; ctx = uint32(ctxNext >> 32)
2028
(local.set $ctx
2129
(i32.wrap_i64 (i64.shr_u (local.get $ctx_next) (i64.const 32))))
2230

2331
(call $handle_response (local.get $ctx) (local.get $is_error))
2432
)
2533

34+
(; end adapter logic ;)
35+
2636
(memory (export "memory") 1 1 (; 1 page==64KB ;))
2737

2838
;; reqCtx is the upper 32-bits of the $ctx_next result the host should

0 commit comments

Comments
 (0)