-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathasync_local.cpp
More file actions
74 lines (62 loc) · 1.68 KB
/
async_local.cpp
File metadata and controls
74 lines (62 loc) · 1.68 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "pch.h"
using namespace winrt;
using namespace Windows::Foundation;
namespace
{
//
// Checks that coroutine locals are destroyed prior to notifying waiters.
//
struct Local
{
bool& destroyed;
~Local()
{
REQUIRE(!destroyed);
destroyed = true;
}
};
IAsyncAction Action(HANDLE event, bool& destroyed)
{
co_await resume_on_signal(event);
Local local{ destroyed };
}
IAsyncActionWithProgress<int> ActionWithProgress(HANDLE event, bool& destroyed)
{
co_await resume_on_signal(event);
Local local{ destroyed };
}
IAsyncOperation<int> Operation(HANDLE event, bool& destroyed)
{
co_await resume_on_signal(event);
Local local{ destroyed };
co_return 1;
}
IAsyncOperationWithProgress<int, int> OperationWithProgress(HANDLE event, bool& destroyed)
{
co_await resume_on_signal(event);
Local local{ destroyed };
co_return 1;
}
template <typename F>
void Check(F make)
{
handle start{ CreateEvent(nullptr, true, false, nullptr) };
handle completed{ CreateEvent(nullptr, true, false, nullptr) };
bool destroyed = false;
auto async = make(start.get(), destroyed);
async.Completed([&](auto&&...)
{
REQUIRE(destroyed);
SetEvent(completed.get());
});
SetEvent(start.get());
REQUIRE(WaitForSingleObject(completed.get(), 1000) == WAIT_OBJECT_0);
}
}
TEST_CASE("async_local")
{
Check(Action);
Check(ActionWithProgress);
Check(Operation);
Check(OperationWithProgress);
}