Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::nodejs::ThreadedAsyncOperation Class Reference

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
 
ThreadedAsyncOperationoperator= (const ThreadedAsyncOperation &)=delete
 
 ThreadedAsyncOperation (ThreadedAsyncOperation &&)=delete
 
ThreadedAsyncOperationoperator= (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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ThreadedAsyncOperation() [1/3]

bb::nodejs::ThreadedAsyncOperation::ThreadedAsyncOperation ( Napi::Env  env,
std::shared_ptr< Napi::Promise::Deferred >  deferred,
async_fn  fn 
)
inline

Definition at line 86 of file async_op.hpp.

◆ ThreadedAsyncOperation() [2/3]

bb::nodejs::ThreadedAsyncOperation::ThreadedAsyncOperation ( const ThreadedAsyncOperation )
delete

◆ ThreadedAsyncOperation() [3/3]

bb::nodejs::ThreadedAsyncOperation::ThreadedAsyncOperation ( ThreadedAsyncOperation &&  )
delete

◆ ~ThreadedAsyncOperation()

bb::nodejs::ThreadedAsyncOperation::~ThreadedAsyncOperation ( )
default

Member Function Documentation

◆ operator=() [1/2]

ThreadedAsyncOperation & bb::nodejs::ThreadedAsyncOperation::operator= ( const ThreadedAsyncOperation )
delete

◆ operator=() [2/2]

ThreadedAsyncOperation & bb::nodejs::ThreadedAsyncOperation::operator= ( ThreadedAsyncOperation &&  )
delete

◆ Queue()

void bb::nodejs::ThreadedAsyncOperation::Queue ( )
inline

Definition at line 103 of file async_op.hpp.

Member Data Documentation

◆ _completion_tsfn

Napi::ThreadSafeFunction bb::nodejs::ThreadedAsyncOperation::_completion_tsfn
private

Definition at line 137 of file async_op.hpp.

◆ _deferred

std::shared_ptr<Napi::Promise::Deferred> bb::nodejs::ThreadedAsyncOperation::_deferred
private

Definition at line 136 of file async_op.hpp.

◆ _error

std::string bb::nodejs::ThreadedAsyncOperation::_error
private

Definition at line 140 of file async_op.hpp.

◆ _fn

async_fn bb::nodejs::ThreadedAsyncOperation::_fn
private

Definition at line 135 of file async_op.hpp.

◆ _result

msgpack::sbuffer bb::nodejs::ThreadedAsyncOperation::_result
private

Definition at line 138 of file async_op.hpp.

◆ _success

bool bb::nodejs::ThreadedAsyncOperation::_success = false
private

Definition at line 139 of file async_op.hpp.


The documentation for this class was generated from the following file: