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
d39ab557
Commit
d39ab557
authored
Nov 16, 2015
by
octal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More work on Promises
parent
955ae9ac
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
384 additions
and
31 deletions
+384
-31
src/async.h
src/async.h
+307
-31
tests/async_test.cc
tests/async_test.cc
+77
-0
No files found.
src/async.h
View file @
d39ab557
This diff is collapsed.
Click to expand it.
tests/async_test.cc
View file @
d39ab557
...
@@ -51,6 +51,32 @@ TEST(async_test, basic_test) {
...
@@ -51,6 +51,32 @@ TEST(async_test, basic_test) {
}
}
TEST
(
async_test
,
void_promise
)
{
Async
::
Promise
<
void
>
p1
(
[](
Async
::
Resolver
&
resolve
,
Async
::
Rejection
&
reject
)
{
resolve
();
});
ASSERT_TRUE
(
p1
.
isFulfilled
());
bool
thenCalled
{
false
};
p1
.
then
([
&
]()
{
thenCalled
=
true
;
},
Async
::
NoExcept
);
ASSERT_TRUE
(
thenCalled
);
Async
::
Promise
<
int
>
p2
(
[](
Async
::
Resolver
&
resolve
,
Async
::
Rejection
&
reject
)
{
ASSERT_THROW
(
resolve
(),
Async
::
Error
);
});
Async
::
Promise
<
void
>
p3
(
[](
Async
::
Resolver
&
resolve
,
Async
::
Rejection
&
reject
)
{
ASSERT_THROW
(
resolve
(
10
),
Async
::
Error
);
});
}
TEST
(
async_test
,
chain_test
)
{
TEST
(
async_test
,
chain_test
)
{
Async
::
Promise
<
int
>
p1
(
Async
::
Promise
<
int
>
p1
(
[](
Async
::
Resolver
&
resolve
,
Async
::
Rejection
&
reject
)
{
[](
Async
::
Resolver
&
resolve
,
Async
::
Rejection
&
reject
)
{
...
@@ -72,5 +98,56 @@ TEST(async_test, chain_test) {
...
@@ -72,5 +98,56 @@ TEST(async_test, chain_test) {
.
then
([](
double
result
)
{
std
::
cout
<<
"Result = "
<<
result
<<
std
::
endl
;
},
.
then
([](
double
result
)
{
std
::
cout
<<
"Result = "
<<
result
<<
std
::
endl
;
},
Async
::
IgnoreException
);
Async
::
IgnoreException
);
enum
class
Test
{
Foo
,
Bar
};
Async
::
Promise
<
Test
>
p3
(
[](
Async
::
Resolver
&
resolve
,
Async
::
Rejection
&
reject
)
{
resolve
(
Test
::
Foo
);
});
p3
.
then
([](
Test
result
)
{
return
Async
::
Promise
<
std
::
string
>
(
[
=
](
Async
::
Resolver
&
resolve
,
Async
::
Rejection
&
)
{
switch
(
result
)
{
case
Test
:
:
Foo
:
resolve
(
std
::
string
(
"Foo"
));
break
;
case
Test
:
:
Bar
:
resolve
(
std
::
string
(
"Bar"
));
}
});
},
Async
::
NoExcept
)
.
then
([](
std
::
string
str
)
{
ASSERT_EQ
(
str
,
"Foo"
);
},
Async
::
NoExcept
);
Async
::
Promise
<
Test
>
p4
(
[](
Async
::
Resolver
&
resolve
,
Async
::
Rejection
&
reject
)
{
resolve
(
Test
::
Bar
);
});
p4
.
then
(
[](
Test
result
)
{
return
Async
::
Promise
<
std
::
string
>
(
[
=
](
Async
::
Resolver
&
resolve
,
Async
::
Rejection
&
reject
)
{
switch
(
result
)
{
case
Test
:
:
Foo
:
resolve
(
std
::
string
(
"Foo"
));
break
;
case
Test
:
:
Bar
:
reject
(
std
::
runtime_error
(
"Invalid"
));
}
});
},
Async
::
NoExcept
)
.
then
(
[](
std
::
string
str
)
{
ASSERT_TRUE
(
false
);
},
[](
std
::
exception_ptr
exc
)
{
ASSERT_THROW
(
std
::
rethrow_exception
(
exc
),
std
::
runtime_error
);
});
}
}
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