Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
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
Operations
Operations
Metrics
Environments
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
cpp-libs
Actor Framework
Commits
037450b4
Commit
037450b4
authored
May 25, 2016
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add example for response promises
parent
fc3ae7ce
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
0 deletions
+50
-0
examples/CMakeLists.txt
examples/CMakeLists.txt
+1
-0
examples/message_passing/promises.cpp
examples/message_passing/promises.cpp
+49
-0
No files found.
examples/CMakeLists.txt
View file @
037450b4
...
...
@@ -30,6 +30,7 @@ add(. hello_world)
add
(
message_passing cell
)
add
(
message_passing divider
)
add
(
message_passing request
)
add
(
message_passing promises
)
add
(
message_passing calculator
)
add
(
message_passing delegating
)
add
(
message_passing fixed_stack
)
...
...
examples/message_passing/promises.cpp
0 → 100644
View file @
037450b4
/******************************************************************************\
* Illustrates response promises. *
\******************************************************************************/
// This file is partially included in the manual, do not modify
// without updating the references in the *.tex files!
// Manual references: lines 18-43 (MessagePassing.tex)
#include <iostream>
#include "caf/all.hpp"
using
std
::
cout
;
using
std
::
endl
;
using
namespace
caf
;
using
add_atom
=
atom_constant
<
atom
(
"add"
)
>
;
using
adder
=
typed_actor
<
replies_to
<
add_atom
,
int
,
int
>::
with
<
int
>>
;
// function-based, statically typed, event-based API
adder
::
behavior_type
worker
()
{
return
{
[](
add_atom
,
int
a
,
int
b
)
{
return
a
+
b
;
}
};
}
// function-based, statically typed, event-based API
adder
::
behavior_type
calculator_master
(
adder
::
pointer
self
)
{
auto
w
=
self
->
spawn
(
worker
);
return
{
[
=
](
add_atom
x
,
int
y
,
int
z
)
->
result
<
int
>
{
auto
rp
=
self
->
make_response_promise
<
int
>
();
self
->
request
(
w
,
infinite
,
x
,
y
,
z
).
then
([
=
](
int
result
)
mutable
{
rp
.
deliver
(
result
);
});
return
rp
;
}
};
}
int
main
(
int
argc
,
char
**
argv
)
{
actor_system
system
{
argc
,
argv
};
auto
f
=
make_function_view
(
system
.
spawn
(
calculator_master
));
cout
<<
"12 + 13 = "
<<
f
(
add_atom
::
value
,
12
,
13
)
<<
endl
;
}
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