Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pistache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
pistache
Commits
efc830c1
Commit
efc830c1
authored
Nov 30, 2015
by
Mathieu Stefani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Async: Resolving a Promise will now throw a BadType if types mismatch
parent
4b72479b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
2 deletions
+18
-2
src/async.h
src/async.h
+17
-1
tests/async_test.cc
tests/async_test.cc
+1
-1
No files found.
src/async.h
View file @
efc830c1
...
...
@@ -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
();
...
...
tests/async_test.cc
View file @
efc830c1
...
...
@@ -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
);
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment