#include <algorithm>
#include <iostream>
#include <string>
{
this_thread::sleep_for( chrono::milliseconds( 10 * str.size() ) );
reverse( str.begin(), str.end() );
so_5::send< string >( reply_ch, str );
} );
}
{
this_thread::sleep_for( chrono::milliseconds( 5 * str.size() * 2 ) );
so_5::send< string >( reply_ch, str + str );
} );
}
void demo()
{
vector< string > strings{ "one", "two", "three", "four" };
thread reverse_thread;
thread doubler_thread;
reverse_cmd_ch, reverse_reply_ch );
reverse_thread = thread{ reverse_worker, reverse_cmd_ch, reverse_reply_ch };
auto reverse_it = strings.begin();
doubler_cmd_ch, doubler_reply_ch );
doubler_thread = thread{ doubler_worker, doubler_cmd_ch, doubler_reply_ch };
auto doubler_it = strings.begin();
so_5::send< string >( reverse_cmd_ch, *(reverse_it++) );
so_5::send< string >( doubler_cmd_ch, *(doubler_it++) );
case_( reverse_reply_ch, [&](
const string & v ) {
cout << "reverse_result: " << v << endl;
if( reverse_it != strings.end() )
so_5::send< string >( reverse_cmd_ch, *(reverse_it++) );
else
} ),
case_( doubler_reply_ch, [&](
const string & v ) {
cout << "doubler_result: " << v << endl;
if( doubler_it != strings.end() )
so_5::send< string >( doubler_cmd_ch, *(doubler_it++) );
else
} ) );
}
int main()
{
try
{
demo();
}
catch( const exception & ex )
{
cerr << "Error: " << ex.what() << endl;
}
return 0;
}