[core] make actor self reference optional - again
- uses a different method of constructor selection that also works on Apple clang < 8.2.
This commit is contained in:
committed by
Ivo van Dongen
parent
2dd8ec8854
commit
68f470fdda
@@ -305,3 +305,34 @@ TEST(Actor, Ask) {
|
||||
ASSERT_EQ(std::future_status::ready, status);
|
||||
ASSERT_EQ(2, result.get());
|
||||
}
|
||||
|
||||
TEST(Actor, NoSelfActorRef) {
|
||||
// Not all actors need a reference to self
|
||||
|
||||
// Trivially constructable
|
||||
struct Trivial {};
|
||||
|
||||
ThreadPool pool { 2 };
|
||||
Actor<Trivial> trivial(pool);
|
||||
|
||||
|
||||
// With arguments
|
||||
struct WithArguments {
|
||||
std::promise<void> promise;
|
||||
|
||||
WithArguments(std::promise<void> promise_)
|
||||
: promise(std::move(promise_)) {
|
||||
}
|
||||
|
||||
void receive() {
|
||||
promise.set_value();
|
||||
}
|
||||
};
|
||||
|
||||
std::promise<void> promise;
|
||||
auto future = promise.get_future();
|
||||
Actor<WithArguments> withArguments(pool, std::move(promise));
|
||||
|
||||
withArguments.invoke(&WithArguments::receive);
|
||||
future.wait();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user