feat update
Some checks failed
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (push) Failing after 2m5s
linux-x64-gcc / linux-gcc (Debug) (push) Failing after 1m59s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Failing after 2m10s
linux-arm-gcc / linux-gcc-armhf (push) Failing after 2m13s
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Successful in 2m28s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 2m33s

This commit is contained in:
tqcq 2024-04-19 21:50:44 +00:00
parent 40a8ffd402
commit 6d15ae737d
2 changed files with 37 additions and 14 deletions

View File

@ -15,10 +15,24 @@ TEST_SUITE("future")
CHECK_EQ(f.Result(), 42); CHECK_EQ(f.Result(), 42);
} }
TEST_CASE("base failed") TEST_CASE("base success 1")
{ {
sled::Promise<int, std::string> p; sled::Promise<int, std::string> p;
auto f = p.GetFuture(); auto f = p.GetFuture().OnSuccess([](int i) { CHECK_EQ(i, 42); }).OnFailure([](const std::string &) {
REQUIRE(false);
});
p.Success(42);
CHECK(f.Wait(-1));
CHECK(f.IsValid());
CHECK_EQ(f.Result(), 42);
}
TEST_CASE("base failed 1")
{
sled::Promise<int, std::string> p;
auto f = p.GetFuture().OnFailure([](const std::string &str) { CHECK_EQ(str, "error"); }).OnSuccess([](int) {
REQUIRE(false);
});
p.Failure("error"); p.Failure("error");
REQUIRE(p.IsFilled()); REQUIRE(p.IsFilled());
REQUIRE(f.IsCompleted()); REQUIRE(f.IsCompleted());
@ -40,7 +54,7 @@ TEST_SUITE("future")
REQUIRE(f.IsFailed()); REQUIRE(f.IsFailed());
CHECK_EQ(f.FailureReason(), "test"); CHECK_EQ(f.FailureReason(), "test");
} }
//
TEST_CASE("base failed") TEST_CASE("base failed")
{ {
sled::Promise<int, std::string> p; sled::Promise<int, std::string> p;

View File

@ -15,14 +15,16 @@ struct is_invocable : std::is_constructible<std::function<void(Args...)>,
}// namespace }// namespace
template<typename FailureT> template<typename FailureT,
typename = typename std::enable_if<!std::is_constructible<FailureT, std::string>::value>::type>
inline FailureT inline FailureT
FailureFromString(std::string &&) FailureFromString(std::string &&)
{ {
return FailureT(); return FailureT();
} }
template<typename FailureT> template<typename FailureT,
typename = typename std::enable_if<std::is_constructible<FailureT, std::string>::value>::type>
inline FailureT inline FailureT
FailureFromString(const std::string &str) FailureFromString(const std::string &str)
{ {
@ -32,18 +34,25 @@ FailureFromString(const std::string &str)
template<> template<>
inline std::string inline std::string
FailureFromString<std::string>(std::string &&str) FailureFromString<std::string>(const std::string &str)
{ {
return std::move(str); return {str};
} }
template<typename FailureT, // template<>
typename = typename std::enable_if<std::is_constructible<FailureT, std::string>::value>::type> // inline std::string
inline FailureT // FailureFromString<std::string>(std::string &&str)
FailureFromString(std::string &&str) // {
{ // return std::move(str);
return FailureT(std::move(str)); // }
}
// template<typename FailureT,
// typename = typename std::enable_if<std::is_constructible<FailureT, std::string>::value>::type>
// inline FailureT
// FailureFromString(std::string &&str)
// {
// return FailureT(std::move(str));
// }
}// namespace failure }// namespace failure