|
Barretenberg
The ZK-SNARK library at the core of Aztec
|
Asynchronous NAPI wrapper for msgpack calls via shared memory IPC. More...
#include <msgpack_client_async.hpp>
Public Member Functions | |
| MsgpackClientAsync (const Napi::CallbackInfo &info) | |
| Napi::Value | setResponseCallback (const Napi::CallbackInfo &info) |
| Set the JavaScript callback to be invoked when responses arrive. | |
| Napi::Value | call (const Napi::CallbackInfo &info) |
| Send a msgpack buffer asynchronously. | |
| Napi::Value | acquire (const Napi::CallbackInfo &info) |
| Acquire a reference to keep the event loop alive Called by TypeScript when there are pending callbacks. | |
| Napi::Value | release (const Napi::CallbackInfo &info) |
| Release a reference to allow the event loop to exit Called by TypeScript when there are no pending callbacks. | |
Static Public Member Functions | |
| static Napi::Function | get_class (Napi::Env env) |
Private Member Functions | |
| void | poll_responses () |
| Background thread function that polls for responses. | |
Private Attributes | |
| std::unique_ptr< bb::ipc::IpcClient > | client_ |
| std::thread | poll_thread_ |
| std::mutex | tsfn_mutex_ |
| Napi::FunctionReference | js_callback_ |
| Napi::ThreadSafeFunction | tsfn_ |
| int | ref_count_ = 0 |
Asynchronous NAPI wrapper for msgpack calls via shared memory IPC.
Provides an asynchronous interface with request pipelining for sending msgpack buffers to the bb binary via shared memory. Multiple requests can be in flight simultaneously, with responses matched to requests in FIFO order by TypeScript.
Architecture (matches socket backend pattern):
This design eliminates the need for C++ mutex/queue by leveraging JavaScript's single-threaded nature for queue management.
Definition at line 27 of file msgpack_client_async.hpp.
| MsgpackClientAsync::MsgpackClientAsync | ( | const Napi::CallbackInfo & | info | ) |
Definition at line 9 of file msgpack_client_async.cpp.
| Napi::Value MsgpackClientAsync::acquire | ( | const Napi::CallbackInfo & | info | ) |
Acquire a reference to keep the event loop alive Called by TypeScript when there are pending callbacks.
Definition at line 125 of file msgpack_client_async.cpp.
| Napi::Value MsgpackClientAsync::call | ( | const Napi::CallbackInfo & | info | ) |
Send a msgpack buffer asynchronously.
| info[0] | - Buffer containing msgpack data |
Writes request to shared memory. TypeScript should create and manage promises.
Definition at line 102 of file msgpack_client_async.cpp.
|
static |
Definition at line 160 of file msgpack_client_async.cpp.
|
private |
Background thread function that polls for responses.
Continuously polls the response ring buffer using recv() with timeout. When a response arrives, invokes the registered JavaScript callback via ThreadSafeFunction. Runs until process exits (thread is detached, no explicit shutdown needed).
Definition at line 52 of file msgpack_client_async.cpp.
| Napi::Value MsgpackClientAsync::release | ( | const Napi::CallbackInfo & | info | ) |
Release a reference to allow the event loop to exit Called by TypeScript when there are no pending callbacks.
Definition at line 145 of file msgpack_client_async.cpp.
| Napi::Value MsgpackClientAsync::setResponseCallback | ( | const Napi::CallbackInfo & | info | ) |
Set the JavaScript callback to be invoked when responses arrive.
| info[0] | - JavaScript function to call with response buffer |
The callback will be invoked from the background thread via ThreadSafeFunction. TypeScript code should use this to resolve promises from its queue.
Definition at line 29 of file msgpack_client_async.cpp.
|
private |
Definition at line 74 of file msgpack_client_async.hpp.
|
private |
Definition at line 83 of file msgpack_client_async.hpp.
|
private |
Definition at line 77 of file msgpack_client_async.hpp.
|
private |
Definition at line 91 of file msgpack_client_async.hpp.
|
private |
Definition at line 87 of file msgpack_client_async.hpp.
|
private |
Definition at line 80 of file msgpack_client_async.hpp.