rogue-runtime 0.1.0

Async RPC Runtime
Documentation
use anyhow::Result;

use rogue_runtime::prelude::*;

rpc! {
    struct ConsumeSelf {
        id: InstanceId,
    }

    impl Identity for ConsumeSelf {
        fn id(&self) -> &InstanceId {
            &self.id
        }
    }

    impl ConsumeSelf {
        pub async fn new() -> Self {
            Self {
                id: InstanceId::new(),
            }
        }

        pub async fn consume(self) {
        }
    }
}

#[tokio::test]
async fn test_consume_self() -> Result<()> {
    // Create a new runtime for the consume self test
    let runtime = Runtime::create("consume_self_test".to_string()).await?;

    // Execute RPC calls locally
    match runtime
        .execute_local(async move {
            let test = ConsumeSelf::new().await;
            let id = test.id();
            let object_ref = ConsumeSelf::create("consume_self_test".into(), *id);
            test.consume().await;
            object_ref.consume().await;
            Ok(())
        })
        .await
    {
        Ok(_) => {
            panic!("instance should have been consumed");
        }
        Err(err) => {
            assert_eq!(err.to_string(), "instance not found".to_string());
        }
    }

    Ok(())
}