Skip to content

Instantly share code, notes, and snippets.

@bassosimone
Created November 17, 2015 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bassosimone/5ccffe4648847e0caf68 to your computer and use it in GitHub Desktop.
Save bassosimone/5ccffe4648847e0caf68 to your computer and use it in GitHub Desktop.
Relight script example
Var<Stream> stream(new Stream(poller));
poller->run([=](std::function<void(std::function<void()>)> stop) {
std::function<void()> cleanup = [=]() {
poller->break_loop();
stream->close();
};
stream->connect_ipv4("127.0.0.1", 8080, [=]() {
stream->on_data([=](Var<Bytes>) {
stream->on_flush([=]() {
stream->write("flushed\n");
stream->on_data([=](Var<Bytes>) {
stop(cleanup);
});
stream->on_flush([]() {});
});
stream->write("received first chunk\n");
});
stream->on_error([=](int err) {
stop(cleanup);
});
}, [=](int err) {
stop(cleanup);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment