I was reading a blog post on the Anthony Williams website when I somehow wandered onto an example of his just::thread library, his barber shop example.
In it he has a series of a structures that doesn't inherit from anything:
struct start_haircut {};
struct no_room {};
struct shop_closed {};
He then has a receive function that he chains the .match() template to:
jss::actor::receive()
.match<start_haircut>(
[&](start_haircut){
//...
})
.match<no_room>(
[&](no_room){
//...
})
.match<shop_closed>(
[&](shop_closed)
{
//...
});
The receive function returns an unspecified_message_receiver object that specifies the type (shop_closed, etc.) and the lambda handler.
What goes inside the receive and match functions? How does the receive and match functions interact?
This is an interesting pattern that can have applications outside the threading model it is used on. I am interested in it for communications over tcp between sensors where small message packets and small amounts of data are being transferred continuously.
Aucun commentaire:
Enregistrer un commentaire