-
Notifications
You must be signed in to change notification settings - Fork 0
actor framework #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NickCody
wants to merge
3
commits into
main
Choose a base branch
from
actor-library
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| load("@rules_cc//cc:defs.bzl", "cc_binary") | ||
| load("@//:global_copts.bzl", "global_copts") | ||
|
|
||
| package(features = ["-default_compile_flags"]) | ||
|
|
||
| cc_binary( | ||
| name = "actor", | ||
| srcs = ["actor.cpp"], | ||
| copts = global_copts(), | ||
| deps = [ | ||
| "@caf//:main", | ||
| "@fmt//:main", | ||
| "@ncurses//:main", | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #include <string> | ||
| #include <iostream> | ||
|
|
||
| #include "caf/actor_ostream.hpp" | ||
| #include "caf/actor_system.hpp" | ||
| #include "caf/caf_main.hpp" | ||
| #include "caf/event_based_actor.hpp" | ||
|
|
||
| using namespace caf; | ||
|
|
||
| behavior mirror(event_based_actor* self) { | ||
| // return the (initial) actor behavior | ||
| return { | ||
| // a handler for messages containing a single string | ||
| // that replies with a string | ||
| [=](const std::string& what) -> std::string { | ||
| // prints "Hello World!" via aout (thread-safe cout wrapper) | ||
| aout(self) << what << std::endl; | ||
| // reply "!dlroW olleH" | ||
| return std::string{what.rbegin(), what.rend()}; | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| void hello_world(event_based_actor* self, const actor& buddy) { | ||
| // send "Hello World!" to our buddy ... | ||
| self->request(buddy, std::chrono::seconds(10), "Hello World!") | ||
| .then( | ||
| // ... wait up to 10s for a response ... | ||
| [=](const std::string& what) { | ||
| // ... and print it | ||
| aout(self) << what << std::endl; | ||
| }); | ||
| } | ||
|
|
||
| void caf_main(actor_system& sys) { | ||
| // create a new actor that calls 'mirror()' | ||
| auto mirror_actor = sys.spawn(mirror); | ||
| // create another actor that calls 'hello_world(mirror_actor)'; | ||
| sys.spawn(hello_world, mirror_actor); | ||
| // the system will wait until both actors are done before exiting the program | ||
| } | ||
|
|
||
| // creates a main function for us that calls our caf_main | ||
| CAF_MAIN() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| load("@rules_cc//cc:defs.bzl", "cc_library") | ||
|
|
||
| cc_library( | ||
| name = "main", | ||
| srcs = [ | ||
| "lib/libcaf_openssl.so.0.18.5", | ||
| "lib/libcaf_io.so", | ||
| "lib/libcaf_openssl.so", | ||
| "lib/libcaf_io.so.0.18.5", | ||
| "lib/libcaf_core.so.0.18.5", | ||
| "lib/libcaf_core.so", | ||
| ], | ||
| visibility = ["//visibility:public"], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #include "include/fmt/format.h" | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ignore |
||
| #include "include/fmt/printf.h" | ||
|
|
||
| #include <memory> | ||
|
|
||
| int main(int /*argc*/, char** /*argv*/) { | ||
|
|
||
| std::unique_ptr<int> pint = std::make_unique<int>(); | ||
| std::shared_ptr<int> spint = std::move(pint); | ||
| *spint = 10; | ||
|
|
||
| fmt::printf("Value is %d\n", *spint); | ||
|
|
||
| return 0; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignore