| ... | @@ -132,56 +132,55 @@ test "@frameSize" { | ... | @@ -132,56 +132,55 @@ test "@frameSize" { |
| 132 | S.doTheTest(); | 132 | S.doTheTest(); |
| 133 | } | 133 | } |
| 134 | | 134 | |
| 135 | //test "coroutine suspend, resume" { | 135 | test "coroutine suspend, resume" { |
| 136 | // seq('a'); | 136 | seq('a'); |
| 137 | // const p = try async<allocator> testAsyncSeq(); | 137 | const p = async testAsyncSeq(); |
| 138 | // seq('c'); | 138 | seq('c'); |
| 139 | // resume p; | 139 | resume p; |
| 140 | // seq('f'); | 140 | seq('f'); |
| 141 | // cancel p; | 141 | // `cancel` is now a suspend point so it cannot be done here |
| 142 | // seq('g'); | 142 | seq('g'); |
| 143 | // | 143 | |
| 144 | // expect(std.mem.eql(u8, points, "abcdefg")); | 144 | expect(std.mem.eql(u8, points, "abcdefg")); |
| 145 | //} | 145 | } |
| 146 | //async fn testAsyncSeq() void { | 146 | async fn testAsyncSeq() void { |
| 147 | // defer seq('e'); | 147 | defer seq('e'); |
| 148 | // | 148 | |
| 149 | // seq('b'); | 149 | seq('b'); |
| 150 | // suspend; | 150 | suspend; |
| 151 | // seq('d'); | 151 | seq('d'); |
| 152 | //} | 152 | } |
| 153 | //var points = [_]u8{0} ** "abcdefg".len; | 153 | var points = [_]u8{0} ** "abcdefg".len; |
| 154 | //var index: usize = 0; | 154 | var index: usize = 0; |
| 155 | // | 155 | |
| 156 | //fn seq(c: u8) void { | 156 | fn seq(c: u8) void { |
| 157 | // points[index] = c; | 157 | points[index] = c; |
| 158 | // index += 1; | 158 | index += 1; |
| 159 | //} | 159 | } |
| 160 | // | 160 | |
| 161 | //test "coroutine suspend with block" { | 161 | test "coroutine suspend with block" { |
| 162 | // const p = try async<allocator> testSuspendBlock(); | 162 | const p = async testSuspendBlock(); |
| 163 | // std.testing.expect(!result); | 163 | expect(!result); |
| 164 | // resume a_promise; | 164 | resume a_promise; |
| 165 | // std.testing.expect(result); | 165 | expect(result); |
| 166 | // cancel p; | 166 | } |
| 167 | //} | 167 | |
| 168 | // | 168 | var a_promise: anyframe = undefined; |
| 169 | //var a_promise: promise = undefined; | 169 | var result = false; |
| 170 | //var result = false; | 170 | async fn testSuspendBlock() void { |
| 171 | //async fn testSuspendBlock() void { | 171 | suspend { |
| 172 | // suspend { | 172 | comptime expect(@typeOf(@frame()) == *@Frame(testSuspendBlock)); |
| 173 | // comptime expect(@typeOf(@handle()) == promise->void); | 173 | a_promise = @frame(); |
| 174 | // a_promise = @handle(); | 174 | } |
| 175 | // } | 175 | |
| 176 | // | 176 | // Test to make sure that @frame() works as advertised (issue #1296) |
| 177 | // //Test to make sure that @handle() works as advertised (issue #1296) | 177 | // var our_handle: anyframe = @frame(); |
| 178 | // //var our_handle: promise = @handle(); | 178 | expect(a_promise == anyframe(@frame())); |
| 179 | // expect(a_promise == @handle()); | 179 | |
| 180 | // | 180 | result = true; |
| 181 | // result = true; | 181 | } |
| 182 | //} | 182 | |
| 183 | // | 183 | //var await_a_promise: anyframe = undefined; |
| 184 | //var await_a_promise: promise = undefined; | | |
| 185 | //var await_final_result: i32 = 0; | 184 | //var await_final_result: i32 = 0; |
| 186 | // | 185 | // |
| 187 | //test "coroutine await" { | 186 | //test "coroutine await" { |
| ... | @@ -204,7 +203,7 @@ test "@frameSize" { | ... | @@ -204,7 +203,7 @@ test "@frameSize" { |
| 204 | // await_seq('c'); | 203 | // await_seq('c'); |
| 205 | // suspend { | 204 | // suspend { |
| 206 | // await_seq('d'); | 205 | // await_seq('d'); |
| 207 | // await_a_promise = @handle(); | 206 | // await_a_promise = @frame(); |
| 208 | // } | 207 | // } |
| 209 | // await_seq('g'); | 208 | // await_seq('g'); |
| 210 | // return 1234; | 209 | // return 1234; |
| ... | @@ -314,14 +313,14 @@ test "@frameSize" { | ... | @@ -314,14 +313,14 @@ test "@frameSize" { |
| 314 | // cancel p2; | 313 | // cancel p2; |
| 315 | //} | 314 | //} |
| 316 | // | 315 | // |
| 317 | //fn nonFailing() (promise->anyerror!void) { | 316 | //fn nonFailing() (anyframe->anyerror!void) { |
| 318 | // return async<std.debug.global_allocator> suspendThenFail() catch unreachable; | 317 | // return async<std.debug.global_allocator> suspendThenFail() catch unreachable; |
| 319 | //} | 318 | //} |
| 320 | //async fn suspendThenFail() anyerror!void { | 319 | //async fn suspendThenFail() anyerror!void { |
| 321 | // suspend; | 320 | // suspend; |
| 322 | // return error.Fail; | 321 | // return error.Fail; |
| 323 | //} | 322 | //} |
| 324 | //async fn printTrace(p: promise->(anyerror!void)) void { | 323 | //async fn printTrace(p: anyframe->(anyerror!void)) void { |
| 325 | // (await p) catch |e| { | 324 | // (await p) catch |e| { |
| 326 | // std.testing.expect(e == error.Fail); | 325 | // std.testing.expect(e == error.Fail); |
| 327 | // if (@errorReturnTrace()) |trace| { | 326 | // if (@errorReturnTrace()) |trace| { |
| ... | @@ -343,7 +342,7 @@ test "@frameSize" { | ... | @@ -343,7 +342,7 @@ test "@frameSize" { |
| 343 | //} | 342 | //} |
| 344 | //async fn testBreakFromSuspend(my_result: *i32) void { | 343 | //async fn testBreakFromSuspend(my_result: *i32) void { |
| 345 | // suspend { | 344 | // suspend { |
| 346 | // resume @handle(); | 345 | // resume @frame(); |
| 347 | // } | 346 | // } |
| 348 | // my_result.* += 1; | 347 | // my_result.* += 1; |
| 349 | // suspend; | 348 | // suspend; |