A C++ library for asynchronous functional programming.
All you need is the >>=
operator.
int main()
{
using namespace wave;
loop main_loop;
idle{} >>= { std::cout << "Hello World!"; };
return 0;
}
idle{2}
>>= ${ std::cout << "This message is twice!"; };
timer{1000}
>>= ${ std::cout << "One second passed!"; };
idle{}
>>= ${ return 1000; }
>>= $(int timeout) { return timer{timeout}; }
>>= ${ std::cout << "Maybe one second passed!"; };
tcp_server server{ 5000 };
std::cout << "Listening..." << std::endl;
server >>= ${
std::cout << "Client connected" << std::endl;
auto client = server.accept();
client << "I send you 50$";
return client;
} >>= $(std::string data) {
std::cout << "Client sent me: " << data << std::endl;
};
tcp_client client{ "127.0.0.1", 5000 };
client.connected() >>= ${
std::cout << "Client connected" << std::endl;
client << "I send you 100$";
return client;
} >>= $(std::string data) {
std::cout << "Server sent me: " << data << std::endl;
};
process<stdout_pipe> ls{"ls", "-l", "/home"};
ls.stdout() >>= $(std::string output) {
std::cout << output;
};