#[try_send]Expand description
Automatically tries to send data via stream after function execution.
This attribute macro tries to send data to the client after the function completes execution. If no argument is provided, the response is built from the context automatically. If an argument is provided, it is used as the data expression to send.
ยงUsage
Using without arguments (default from context):
use hyperlane::*;
use hyperlane_macros::*;
#[route("/try_send")]
struct TrySendTest;
impl ServerHook for TrySendTest {
async fn new(_: &mut Stream, _: &mut Context) -> Self {
Self
}
#[epilogue_macros(try_send)]
async fn handle(self, stream: &mut Stream, ctx: &mut Context) -> Status { Status::Continue }
}
impl TrySendTest {
#[try_send]
async fn try_send_with_ref_self(&self, stream: &mut Stream, ctx: &mut Context) -> Status { Status::Continue }
}
#[try_send]
async fn standalone_try_send_handler(stream: &mut Stream, ctx: &mut Context) -> Status { Status::Continue }Using with a data expression:
use hyperlane::*;
use hyperlane_macros::*;
#[route("/try_send_with_data")]
struct TrySendWithDataTest;
impl ServerHook for TrySendWithDataTest {
async fn new(_: &mut Stream, _: &mut Context) -> Self {
Self
}
#[epilogue_macros(try_send(ctx.get_mut_response().build()))]
async fn handle(self, stream: &mut Stream, ctx: &mut Context) -> Status { Status::Continue }
}The macro accepts an optional data expression. If omitted, it defaults to sending the response built from the context.