ObjectBox C and C++ API  4.0.3
obx::AsyncBox< EntityT > Class Template Reference

AsyncBox provides asynchronous ("happening on the background") database manipulation. More...

#include <objectbox.hpp>

Public Member Functions

 AsyncBox (Store &store, uint64_t enqueueTimeoutMillis)
 Create a custom AsyncBox instance. Prefer using Box::async() for standard tasks, it gives you a shared instance. More...
 
 AsyncBox (AsyncBox &&source) noexcept
 Move constructor. More...
 
 AsyncBox (const AsyncBox &)=delete
 Can't be copied, single owner of C resources is required (to avoid double-free during destruction) More...
 
virtual ~AsyncBox ()
 
OBX_asynccPtr () const
 
obx_id put (EntityT &object, OBXPutMode mode=OBXPutMode_PUT)
 Reserve an ID, which is returned immediately for future reference, and insert asynchronously. Note: of course, it can NOT be guaranteed that the entity will actually be inserted successfully in the DB. More...
 
obx_id put (const EntityT &object, OBXPutMode mode=OBXPutMode_PUT)
 Reserve an ID, which is returned immediately for future reference and put asynchronously. Note: of course, it can NOT be guaranteed that the entity will actually be put successfully in the DB. More...
 
void remove (obx_id id)
 Asynchronously remove the object with the given id. More...
 
bool awaitCompletion ()
 Await for all (including future) async submissions to be completed (the async queue becomes idle for a moment). Currently this is not limited to the single entity this AsyncBox is working on but all entities in the store. More...
 
bool awaitSubmitted ()
 Await for previously submitted async operations to be completed (the async queue does not have to become idle). Currently this is not limited to the single entity this AsyncBox is working on but all entities in the store. More...
 

Detailed Description

template<typename EntityT>
class obx::AsyncBox< EntityT >

AsyncBox provides asynchronous ("happening on the background") database manipulation.

Constructor & Destructor Documentation

◆ AsyncBox() [1/3]

template<typename EntityT >
obx::AsyncBox< EntityT >::AsyncBox ( Store store,
uint64_t  enqueueTimeoutMillis 
)
inline

Create a custom AsyncBox instance. Prefer using Box::async() for standard tasks, it gives you a shared instance.

◆ AsyncBox() [2/3]

template<typename EntityT >
obx::AsyncBox< EntityT >::AsyncBox ( AsyncBox< EntityT > &&  source)
inlinenoexcept

Move constructor.

◆ AsyncBox() [3/3]

template<typename EntityT >
obx::AsyncBox< EntityT >::AsyncBox ( const AsyncBox< EntityT > &  )
delete

Can't be copied, single owner of C resources is required (to avoid double-free during destruction)

◆ ~AsyncBox()

template<typename EntityT >
virtual obx::AsyncBox< EntityT >::~AsyncBox ( )
inlinevirtual

Member Function Documentation

◆ awaitCompletion()

template<typename EntityT >
bool obx::AsyncBox< EntityT >::awaitCompletion ( )
inline

Await for all (including future) async submissions to be completed (the async queue becomes idle for a moment). Currently this is not limited to the single entity this AsyncBox is working on but all entities in the store.

Returns
true if all submissions were completed or async processing was not started; false if shutting down
false if shutting down or an error occurred

◆ awaitSubmitted()

template<typename EntityT >
bool obx::AsyncBox< EntityT >::awaitSubmitted ( )
inline

Await for previously submitted async operations to be completed (the async queue does not have to become idle). Currently this is not limited to the single entity this AsyncBox is working on but all entities in the store.

Returns
true if all submissions were completed or async processing was not started
false if shutting down or an error occurred

◆ cPtr()

template<typename EntityT >
OBX_async* obx::AsyncBox< EntityT >::cPtr ( ) const
inline

◆ put() [1/2]

template<typename EntityT >
obx_id obx::AsyncBox< EntityT >::put ( const EntityT &  object,
OBXPutMode  mode = OBXPutMode_PUT 
)
inline

Reserve an ID, which is returned immediately for future reference and put asynchronously. Note: of course, it can NOT be guaranteed that the entity will actually be put successfully in the DB.

Parameters
mode- use INSERT or PUT; in case you need to use UPDATE, use the C-API directly for now
Returns
the reserved ID which will be used for the object if the asynchronous insert succeeds.

◆ put() [2/2]

template<typename EntityT >
obx_id obx::AsyncBox< EntityT >::put ( EntityT &  object,
OBXPutMode  mode = OBXPutMode_PUT 
)
inline

Reserve an ID, which is returned immediately for future reference, and insert asynchronously. Note: of course, it can NOT be guaranteed that the entity will actually be inserted successfully in the DB.

Parameters
objectwill be updated with the reserved ID.
Returns
the reserved ID which will be used for the object if the asynchronous insert succeeds.

◆ remove()

template<typename EntityT >
void obx::AsyncBox< EntityT >::remove ( obx_id  id)
inline

Asynchronously remove the object with the given id.