summaryrefslogtreecommitdiff
path: root/crates/vcs_actions/src/actions/local_actions.rs
blob: b11a93477f022a0a4748c800d2f06644024f5f22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use action_system::{action::ActionContext, action_gen};
use log::info;
use tcp_connection::error::TcpTargetError;

#[action_gen]
pub async fn hello_world_action(ctx: ActionContext, _n: ()) -> Result<(), TcpTargetError> {
    // Ensure the instance is available
    let Some(instance) = ctx.instance() else {
        return Err(TcpTargetError::NotFound(
            "Connection Instance Lost.".to_string(),
        ));
    };

    if ctx.is_local() {
        // Invoke on local
        // Send the message to the server
        let _ = instance.lock().await.write_text("Hello World!").await;
    } else if ctx.is_remote() {
        // Read the message from the client
        let read = instance.lock().await.read_text().await?;
        info!("{}", read)
    }

    Ok(())
}