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
5455a471
Commit
5455a471
authored
Nov 12, 2015
by
octal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A promise is not attached to its core anymore
parent
c9a8e990
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
8 additions
and
32 deletions
+8
-32
src/async.h
src/async.h
+0
-26
src/http.cc
src/http.cc
+2
-3
src/http.h
src/http.h
+1
-0
tests/async_test.cc
tests/async_test.cc
+5
-3
No files found.
src/async.h
View file @
5455a471
...
...
@@ -76,28 +76,12 @@ namespace Async {
struct
Core
{
Core
(
State
state
)
:
state
(
state
)
,
promise
(
nullptr
)
{
}
State
state
;
std
::
exception_ptr
exc
;
PromiseBase
*
promise
;
std
::
vector
<
std
::
shared_ptr
<
Request
>>
requests
;
void
attach
(
PromiseBase
*
p
)
{
if
(
promise
)
throw
Error
(
"Trying to double-attach a Promise"
);
promise
=
p
;
}
void
detach
()
{
if
(
!
promise
)
throw
Error
(
"Trying to detach a non attached Promise"
);
promise
=
nullptr
;
}
virtual
void
*
memory
()
=
0
;
};
...
...
@@ -113,9 +97,6 @@ namespace Async {
bool
operator
()(
Arg
&&
arg
)
{
typedef
typename
std
::
remove_reference
<
Arg
>::
type
Type
;
auto
promise
=
core_
->
promise
;
if
(
!
promise
)
return
false
;
if
(
core_
->
state
!=
State
::
Pending
)
throw
Error
(
"Attempt to resolve a fulfilled promise"
);
...
...
@@ -142,10 +123,6 @@ namespace Async {
template
<
typename
Exc
>
bool
operator
()(
Exc
exc
)
{
auto
promise
=
core_
->
promise
;
if
(
!
promise
)
return
false
;
if
(
core_
->
state
!=
State
::
Pending
)
throw
Error
(
"Attempt to reject a fulfilled promise"
);
...
...
@@ -196,7 +173,6 @@ namespace Async {
,
resolver_
(
core_
)
,
rejection_
(
core_
)
{
core_
->
attach
(
this
);
func
(
resolver_
,
rejection_
);
}
...
...
@@ -208,7 +184,6 @@ namespace Async {
~
Promise
()
{
core_
->
detach
();
}
bool
isPending
()
const
{
return
core_
->
state
==
State
::
Pending
;
}
...
...
@@ -273,7 +248,6 @@ namespace Async {
,
resolver_
(
core
)
,
rejection_
(
core
)
{
core_
->
attach
(
this
);
}
...
...
src/http.cc
View file @
5455a471
...
...
@@ -369,8 +369,7 @@ Response::send(Code code) {
Async
::
Promise
<
ssize_t
>
Response
::
send
(
Code
code
,
const
std
::
string
&
body
,
const
Mime
::
MediaType
&
mime
)
{
char
buffer
[
Const
::
MaxBuffer
];
Io
::
OutArrayBuf
obuf
(
buffer
,
Io
::
Init
::
ZeroOut
);
Io
::
OutArrayBuf
obuf
(
buffer_
,
Io
::
Init
::
ZeroOut
);
std
::
ostream
stream
(
&
obuf
);
stream
<<
"HTTP/1.1 "
;
...
...
@@ -403,7 +402,7 @@ Response::send(Code code, const std::string& body, const Mime::MediaType& mime)
stream
<<
crlf
;
}
return
peer
()
->
send
(
buffer
,
obuf
.
len
());
return
peer
()
->
send
(
buffer
_
,
obuf
.
len
());
}
void
...
...
src/http.h
View file @
5455a471
...
...
@@ -107,6 +107,7 @@ private:
void
associatePeer
(
const
std
::
shared_ptr
<
Tcp
::
Peer
>&
peer
);
std
::
weak_ptr
<
Tcp
::
Peer
>
peer_
;
char
buffer_
[
Const
::
MaxBuffer
];
};
namespace
Private
{
...
...
tests/async_test.cc
View file @
5455a471
...
...
@@ -30,9 +30,11 @@ TEST(async_test, basic_test) {
p1
.
then
([
&
](
int
v
)
{
val
=
v
;
},
Async
::
NoExcept
);
ASSERT_EQ
(
val
,
10
);
{
Async
::
Promise
<
int
>
p2
=
doAsync
(
10
);
p2
.
then
([](
int
result
)
{
ASSERT_EQ
(
result
,
20
);
},
Async
::
NoExcept
);
}
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
2
));
...
...
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