Understanding the CAF actor function that returns void

I know that actors can be implemented by function. The following code snippet from CAF examples is github / hello_world.cpp .

I know the first implementation method that associates a pair of message handlers with an actor. The actor will be alive in the background and triggered by events, and then terminated when called self->quit.

But the second returns nothing, where is its message handler? And it looks like no- self->quitlike function ends. Is he alive when hello_world returns? Or does it just end after completing the answer in then?

behavior mirror(event_based_actor* self) {  
    return {
        [=](const string& what) { ... } 
        [=](int) { ...}            
    }
};

void hello_world(event_based_actor* self, const actor& buddy) {  
    self->sync_send(...).then(
        ...
    );
}

int main() {  
    auto mirror_actor = spawn(mirror); 
    spawn(hello_world, mirror_actor);                
    await_all_actors_done();
    shutdown();
}

Update

An actor will terminate itself if not a message handler in its behavior stack.

hello_word . , . sync_send then-behavior , . , then-behavior , , , , .

+4
1

, ? , self->quit - . , hello_world? ?

hello_world void, behavior, , , , . :

  • sync_send.
  • .
  • .
+4

Source: https://habr.com/ru/post/1620563/


All Articles