-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathcoroutines.cpp
More file actions
58 lines (47 loc) · 982 Bytes
/
coroutines.cpp
File metadata and controls
58 lines (47 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "pch.h"
import std;
import winrt.Windows.Foundation;
using namespace winrt;
using namespace Windows::Foundation;
IAsyncAction do_nothing_async()
{
co_return;
}
IAsyncOperation<int> return_42_async()
{
co_return 42;
}
IAsyncOperation<hstring> return_string_async()
{
co_return L"module coroutine";
}
IAsyncAction chain_async()
{
auto result = co_await return_string_async();
REQUIRE(!result.empty());
}
IAsyncOperation<int> slow_operation()
{
co_await resume_after(std::chrono::hours(1));
co_return 0;
}
TEST_CASE("module_async_action")
{
auto action = do_nothing_async();
action.get();
REQUIRE(action.Status() == AsyncStatus::Completed);
}
TEST_CASE("module_async_operation")
{
REQUIRE(return_42_async().get() == 42);
}
TEST_CASE("module_async_chain")
{
chain_async().get();
}
TEST_CASE("module_async_cancel")
{
auto op = slow_operation();
op.Cancel();
REQUIRE(op.Status() == AsyncStatus::Canceled);
}