1;;! component_model_async = true 2 3;; Create a future, start a write, drop the read end, and cancel the write. 4(component 5 (type $f (future)) 6 (core func $new (canon future.new $f)) 7 (core module $libc (memory (export "mem") 1)) 8 (core instance $libc (instantiate $libc)) 9 (core func $write (canon future.write $f async (memory $libc "mem"))) 10 (core func $cancel (canon future.cancel-write $f)) 11 (core func $drop-read (canon future.drop-readable $f)) 12 (core module $m 13 (import "" "new" (func $new (result i64))) 14 (import "" "write" (func $write (param i32 i32) (result i32))) 15 (import "" "cancel" (func $cancel (param i32) (result i32))) 16 (import "" "drop-read" (func $drop-read (param i32))) 17 18 (func (export "f") (result i32) 19 (local $read i32) 20 (local $write i32) 21 (local $new i64) 22 23 (local.set $new (call $new)) 24 (local.set $read (i32.wrap_i64 (local.get $new))) 25 (local.set $write (i32.wrap_i64 (i64.shr_u (local.get $new) (i64.const 32)))) 26 27 ;; start a write 28 local.get $write 29 i32.const 0 30 call $write 31 i32.const -1 32 i32.ne 33 if unreachable end 34 35 ;; drop the read end 36 local.get $read 37 call $drop-read 38 39 ;; cancel the write, returning the result 40 local.get $write 41 call $cancel 42 ) 43 ) 44 45 (core instance $i (instantiate $m 46 (with "" (instance 47 (export "new" (func $new)) 48 (export "write" (func $write)) 49 (export "cancel" (func $cancel)) 50 (export "drop-read" (func $drop-read)) 51 )) 52 )) 53 54 (func (export "f") async (result u32) (canon lift (core func $i "f"))) 55) 56 57(assert_return (invoke "f") (u32.const 1)) ;; expect DROPPED status (not CANCELLED) 58