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

Encapsulatest some work that can be done off the JavaScript main thread. More...

#include <async_op.hpp>

Inheritance diagram for bb::nodejs::AsyncOperation:

Public Member Functions

 AsyncOperation (Napi::Env env, std::shared_ptr< Napi::Promise::Deferred > deferred, async_fn fn)
 
 AsyncOperation (const AsyncOperation &)=delete
 
AsyncOperationoperator= (const AsyncOperation &)=delete
 
 AsyncOperation (AsyncOperation &&)=delete
 
AsyncOperationoperator= (AsyncOperation &&)=delete
 
 ~AsyncOperation () override=default
 
void Execute () override
 
void OnOK () override
 
void OnError (const Napi::Error &e) override
 

Private Attributes

async_fn _fn
 
std::shared_ptr< Napi::Promise::Deferred > _deferred
 
msgpack::sbuffer _result
 

Detailed Description

Encapsulatest some work that can be done off the JavaScript main thread.

This class takes a Deferred instance (i.e. a Promise to JS), execute some work in a separate thread, and then report back on the result. The async execution must not touch the JS environment. Everything that's needed to complete the work must be copied into memory owned by the C++ code. The same has to be done when reporting back the result: keep the result in memory owned by the C++ code and copy it back to the JS environment in the OnOK/OnError methods.

OnOK/OnError will be called on the main JS thread, so it's safe to interact with the JS environment there.

Instances of this class are managed by the NodeJS environment and execute on a libuv thread. Docs . - https://github.com/nodejs/node-addon-api/blob/cc06369aa4dd29e585600b8b47839c1297df962d/doc/async_worker.md . - https://nodejs.github.io/node-addon-examples/special-topics/asyncworker

Definition at line 27 of file async_op.hpp.

Constructor & Destructor Documentation

◆ AsyncOperation() [1/3]

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

Definition at line 29 of file async_op.hpp.

◆ AsyncOperation() [2/3]

bb::nodejs::AsyncOperation::AsyncOperation ( const AsyncOperation )
delete

◆ AsyncOperation() [3/3]

bb::nodejs::AsyncOperation::AsyncOperation ( AsyncOperation &&  )
delete

◆ ~AsyncOperation()

bb::nodejs::AsyncOperation::~AsyncOperation ( )
overridedefault

Member Function Documentation

◆ Execute()

void bb::nodejs::AsyncOperation::Execute ( )
inlineoverride

Definition at line 42 of file async_op.hpp.

◆ OnError()

void bb::nodejs::AsyncOperation::OnError ( const Napi::Error &  e)
inlineoverride

Definition at line 56 of file async_op.hpp.

◆ OnOK()

void bb::nodejs::AsyncOperation::OnOK ( )
inlineoverride

Definition at line 51 of file async_op.hpp.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

Member Data Documentation

◆ _deferred

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

Definition at line 60 of file async_op.hpp.

◆ _fn

async_fn bb::nodejs::AsyncOperation::_fn
private

Definition at line 59 of file async_op.hpp.

◆ _result

msgpack::sbuffer bb::nodejs::AsyncOperation::_result
private

Definition at line 61 of file async_op.hpp.


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