-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
81 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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,19 @@ | ||
#include "CustomClass.h" | ||
|
||
CustomClass::CustomClass(int a, int b) : counterA{ a }, counterB{ b } {} | ||
|
||
void CustomClass::incrementA() { | ||
++counterA; | ||
} | ||
|
||
void CustomClass::incrementB() { | ||
++counterB; | ||
} | ||
|
||
int CustomClass::getA() { | ||
return counterA; | ||
} | ||
|
||
int CustomClass::getB() { | ||
return counterB; | ||
} |
This file contains 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 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,52 @@ | ||
#include "client.h" | ||
#include "CustomClass.h" | ||
|
||
using namespace std; | ||
|
||
#include <future> | ||
|
||
int main() | ||
{ | ||
cout << "I am the async client." << endl; | ||
|
||
const auto policy{ std::launch::async }; | ||
|
||
// sends | ||
|
||
auto intSend{ std::async(policy, []() { | ||
send("mykeyasync", 101); | ||
}) }; | ||
|
||
auto strSend{ std::async(policy, []() { | ||
send("she", string{ "ra" }); | ||
}) }; | ||
|
||
auto customSend{ std::async(policy, []() { | ||
CustomClass custom{ 42, 81 }; | ||
custom.incrementA(); | ||
custom.incrementB(); | ||
send("mycustomclassasync", custom); | ||
}) }; | ||
|
||
// gets | ||
|
||
auto intGet{ std::async(policy, [&intSend]() { | ||
intSend.get(); // await send success | ||
cout << get<int>("mykeyasync") << endl; | ||
}) }; | ||
|
||
auto strGet{ std::async(policy, [&strSend]() { | ||
strSend.get(); // await send success | ||
cout << get<string>("she") << endl; | ||
}) }; | ||
|
||
auto customGet{ std::async(policy, [&customSend]() { | ||
customSend.get(); // await send success | ||
auto savedCustom{ get<CustomClass>("mycustomclassasync") }; | ||
savedCustom.incrementA(); | ||
savedCustom.incrementB(); | ||
cout << savedCustom.getA() << endl << savedCustom.getB() << endl; | ||
}) }; | ||
|
||
getchar(); // wait before closing | ||
} |
This file contains 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