|
Barretenberg
The ZK-SNARK library at the core of Aztec
|
Runs work on a dedicated std::thread instead of the libuv thread pool. More...
#include <async_op.hpp>
Public Member Functions | |
| ThreadedAsyncOperation (Napi::Env env, std::shared_ptr< Napi::Promise::Deferred > deferred, async_fn fn) | |
| ThreadedAsyncOperation (const ThreadedAsyncOperation &)=delete | |
| ThreadedAsyncOperation & | operator= (const ThreadedAsyncOperation &)=delete |
| ThreadedAsyncOperation (ThreadedAsyncOperation &&)=delete | |
| ThreadedAsyncOperation & | operator= (ThreadedAsyncOperation &&)=delete |
| ~ThreadedAsyncOperation ()=default | |
Static Public Member Functions | |
| static void | Run (Napi::Env env, std::shared_ptr< Napi::Promise::Deferred > deferred, async_fn fn) |
Private Member Functions | |
| void | Queue () |
Private Attributes | |
| async_fn | _fn |
| std::shared_ptr< Napi::Promise::Deferred > | _deferred |
| Napi::ThreadSafeFunction | _completion_tsfn |
| msgpack::sbuffer | _result |
| bool | _success = false |
| std::string | _error |
Runs work on a dedicated std::thread instead of the libuv thread pool.
Unlike AsyncOperation (which uses Napi::AsyncWorker and occupies a libuv thread), this class spawns a new OS thread for each operation. This prevents AVM simulations from exhausting the libuv thread pool, which would deadlock when C++ callbacks need to invoke JS functions that themselves require libuv threads (e.g., LMDB reads).
The completion callback (resolve/reject) is posted back to the JS main thread via a Napi::ThreadSafeFunction, so the event loop returns immediately after launch and is woken up only when the work is done.
Prevent use-after-free: the TSFN callback runs asynchronously on the JS thread (napi_tsfn_blocking only blocks on queue insertion, NOT on callback completion). Both the worker thread lambda and the callback capture a shared_ptr to keep the object alive until both are done.
Usage: ThreadedAsyncOperation::Run(env, deferred, fn);
Definition at line 88 of file async_op.hpp.
|
inline |
Definition at line 90 of file async_op.hpp.
|
delete |
|
delete |
|
default |
|
delete |
|
delete |
|
inlineprivate |
Definition at line 112 of file async_op.hpp.
|
inlinestatic |
Definition at line 105 of file async_op.hpp.
|
private |
Definition at line 146 of file async_op.hpp.
|
private |
Definition at line 145 of file async_op.hpp.
|
private |
Definition at line 149 of file async_op.hpp.
|
private |
Definition at line 144 of file async_op.hpp.
|
private |
Definition at line 147 of file async_op.hpp.
|
private |
Definition at line 148 of file async_op.hpp.