run_with_await.carbon 541 B

12345678910111213141516171819202122232425
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. // RUN: %{explorer-run}
  7. // RUN: %{explorer-run-trace}
  8. // CHECK:STDOUT: result: 3
  9. package ExplorerTest api;
  10. // Test pausing a continuation with `__await` and restarting it with
  11. // `__run`.
  12. fn Main() -> i32 {
  13. var x: i32 = 0;
  14. __continuation k {
  15. x = x + 1;
  16. __await;
  17. x = x + 2;
  18. }
  19. __run k;
  20. __run k;
  21. return x;
  22. }