-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors_async.hpp
32 lines (26 loc) · 1.8 KB
/
errors_async.hpp
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
#pragma once
#include <expected>
#include "ws_client/errors.hpp"
namespace ws_client
{
#define WS_CO_TRY(VARIABLE, EXPRESSION) \
auto&& VARIABLE = (EXPRESSION); \
if (!(VARIABLE).has_value()) [[unlikely]] \
co_return std::unexpected((VARIABLE).error());
#define WS_CO_TRY_RAW(VARIABLE, EXPRESSION) \
auto&& VARIABLE = (EXPRESSION); \
if (!(VARIABLE).has_value()) [[unlikely]] \
co_return (VARIABLE).error();
#define WS_CO_TRYV(EXPRESSION) \
{ \
auto&& tmp = (EXPRESSION); \
if (!tmp.has_value()) [[unlikely]] \
co_return std::unexpected(tmp.error()); \
}
#define WS_CO_TRYV_RAW(EXPRESSION) \
{ \
auto&& tmp = (EXPRESSION); \
if (!tmp.has_value()) [[unlikely]] \
co_return tmp.error(); \
}
} // namespace ws_client