mapping_async_block.adl
1 program test.alpha { 2 mapping map: u32 => u32; 3 async transition main() -> (u32, Future) { 4 let x = 5u32; 5 let f = async { 6 map.set(0u32, 42u32); 7 assert(map.get(0u32) == 42u32); 8 map.set(1u32, map.get(0u32) + x); 9 assert(x == 5); // ensure we're using the old value of `x` not the updated one after the async block 10 x = 6; // ensure we're able to update `x` in here 11 assert(x == 6); 12 assert(map.get(1u32) == 42u32 + x - 1); 13 }; 14 assert(x == 5); // ensure `x` still has its old value 15 x = 7; 16 assert(x == 7); 17 18 // Ensures that that the async block is actually executed (including the asserts). 19 // This is technically illegal since `await` is not allowed in a transition. However, for testing purposes, this 20 // seems fine for now. We should improve this when we have better testing infra for the interpreter 21 f.await(); 22 23 assert(x == 7); // x should still have its value update outside the async block 24 return (x, f); 25 } 26 }