Created
November 17, 2015 10:30
-
-
Save bassosimone/5ccffe4648847e0caf68 to your computer and use it in GitHub Desktop.
Relight script example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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