|
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 | |
| 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.
Usage: auto* op = new ThreadedAsyncOperation(env, deferred, fn); op->Queue(); The object self-destructs after resolving/rejecting the promise.
Definition at line 84 of file async_op.hpp.
|
inline |
Definition at line 86 of file async_op.hpp.
|
delete |
|
delete |
|
default |
|
delete |
|
delete |
|
inline |
Definition at line 103 of file async_op.hpp.
|
private |
Definition at line 137 of file async_op.hpp.
|
private |
Definition at line 136 of file async_op.hpp.
|
private |
Definition at line 140 of file async_op.hpp.
|
private |
Definition at line 135 of file async_op.hpp.
|
private |
Definition at line 138 of file async_op.hpp.
|
private |
Definition at line 139 of file async_op.hpp.