Skip to content

feat(rpc_loader): Add async support for RPC function calls#623

Open
Mag-D-Anas wants to merge 1 commit intometacall:developfrom
Mag-D-Anas:feature/rpc-async-support
Open

feat(rpc_loader): Add async support for RPC function calls#623
Mag-D-Anas wants to merge 1 commit intometacall:developfrom
Mag-D-Anas:feature/rpc-async-support

Conversation

@Mag-D-Anas
Copy link

feat(rpc_loader): Add async support for RPC function calls

Summary

This PR implements the previously unimplemented function_rpc_interface_await function in the RPC loader, enabling non-blocking asynchronous remote procedure calls. This is a foundational step towards the Function Mesh concept - allowing applications to be split across multiple servers while maintaining transparent function call semantics.

Motivation

The RPC loader previously only supported synchronous function calls, which block the calling thread until the remote server responds. For long-running remote operations, this creates performance bottlenecks. Async support enables:

  • Non-blocking remote calls
  • Better resource utilization
  • Foundation for distributed function orchestration

Changes

source/loaders/rpc_loader/source/rpc_loader_impl.cpp

  • Implemented function_rpc_interface_await using std::thread for async HTTP calls
  • Added #include <thread> for threading support
  • Each async call spawns a detached thread that:
    • Creates its own CURL handle (CURL handles are not thread-safe)
    • Performs the HTTP POST to /await/{function_name}
    • Deserializes the response
    • Calls resolve_callback on success or reject_callback on failure
  • Proper memory management with deep-copied arguments for thread safety

source/tests/metacall_rpc_test/source/server.js

  • Added async_divide function with "async": true in inspect response
  • Added /await/async_divide POST endpoint handler
  • Simulates async processing with 100ms delay

Threading Strategy: Uses std::thread with detached threads. Each async call:

  1. Deep copies arguments to avoid use-after-free
  2. Serializes arguments to JSON
  3. Creates thread-local CURL handle
  4. Performs blocking HTTP call inside thread
  5. Deserializes response and invokes callback

Testing

Future Considerations

  • Consider CURL multi-handle for more efficient async I/O (single thread, event-driven)
  • Add timeout handling for async calls
  • Thread pool instead of spawning new threads per call

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant