|
FastLED 3.9.15
|
Helper class for sending responses in async/streaming RPC methods.
ResponseSend provides a simple API for async RPC methods to send responses:
The request ID is automatically attached to all responses.
EXAMPLE USAGE (ASYNC mode):
remote.bindAsync("longTask", [](ResponseSend& send, int param) { // ACK is already sent automatically
// Do work... int result = doLongWork(param);
// Send final result send.send(json::object().set("value", result)); });
EXAMPLE USAGE (ASYNC_STREAM mode):
remote.bindAsync("streamData", [](ResponseSend& send, int count) { // ACK is already sent automatically
// Send multiple updates for (int i = 0; i < count; i++) { send.sendUpdate(json::object().set("progress", i * 10)); }
// Send final result send.sendFinal(json::object().set("done", true)); }, RpcMode::ASYNC_STREAM);
Definition at line 45 of file response_send.h.
#include <response_send.h>
Collaboration diagram for fl::ResponseSend:Public Member Functions | |
| ResponseSend (const fl::json &requestId, fl::function< void(const fl::json &)> sink) | |
| Construct ResponseSend with request ID and response sink. | |
| ResponseSend (const ResponseSend &) FL_NOEXCEPT=delete | |
| ResponseSend (ResponseSend &&) FL_NOEXCEPT=default | |
| bool | isFinal () const |
| Check if final response has been sent. | |
| ResponseSend & | operator= (const ResponseSend &) FL_NOEXCEPT=delete |
| ResponseSend & | operator= (ResponseSend &&) FL_NOEXCEPT=default |
| const fl::json & | requestId () const |
| Get the request ID. | |
| void | send (const fl::json &result) |
| Send a single response (for ASYNC mode) | |
| void | sendFinal (const fl::json &result) |
| Send final response and mark stream as complete (for ASYNC_STREAM mode) | |
| void | sendUpdate (const fl::json &update) |
| Send intermediate streaming update (for ASYNC_STREAM mode) | |
Private Attributes | |
| bool | mIsFinal |
| fl::json | mRequestId |
| fl::function< void(const fl::json &)> | mResponseSink |