Commit efc830c1 authored by Mathieu Stefani's avatar Mathieu Stefani

Async: Resolving a Promise will now throw a BadType if types mismatch

parent 4b72479b
......@@ -22,6 +22,22 @@ namespace Async {
explicit Error(const std::string& what) : std::runtime_error(what) { }
};
class BadType : public Error {
public:
BadType(TypeId id)
: Error("Argument type can not be used to resolve the promise "
" (TypeId does not match)")
, id_(std::move(id))
{ }
TypeId typeId() const {
return id_;
}
private:
TypeId id_;
};
/*
- Direct: The continuation will be directly called in the context
of the same thread
......@@ -140,7 +156,7 @@ namespace Async {
throw Error("Can not construct a void core");
if (id != TypeId::of<T>()) {
throw Error("Bad value type");
throw BadType(id);
}
void *mem = memory();
......
......@@ -61,7 +61,7 @@ TEST(async_test, basic_test) {
TEST(async_test, error_test) {
Async::Promise<int> p1(
[](Async::Resolver& resolve, Async::Rejection& reject) {
ASSERT_THROW(resolve(10.5), Async::Error);
ASSERT_THROW(resolve(10.5), Async::BadType);
});
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment