putQueued method

int putQueued(
  1. T object, {
  2. PutMode mode = PutMode.put,
})

Schedules the given object to be put later on, by an asynchronous queue.

The actual database put operation may fail even if this function returned normally (and even if it returned a new ID for a new object). For example if the database put failed because of a unique constraint violation. Therefore, you should make sure the data you put is correct and you have a fall back in place even if it eventually failed.

In extreme scenarios (e.g. having hundreds of thousands async operations per second), this may fail as internal queues fill up if the disk can't keep up. However, this should not be a concern for typical apps.

See also putAsync which returns a Future that only completes after an actual database put was successful. Use Store.awaitAsyncCompletion and Store.awaitAsyncSubmitted to wait until all operations have finished.

Implementation

int putQueued(T object, {PutMode mode = PutMode.put}) {
  if (_hasRelations) {
    throw UnsupportedError('putQueued() is currently not supported on entity '
        '${T.toString()} because it has relations.');
  }
  _async ??= _AsyncBoxHelper(this);

  _builder.fbb.reset();
  var id = _entity.objectToFB(object, _builder.fbb);
  final newId = C.async_put_object4(_async!._cAsync, _builder.bufPtr,
      _builder.fbb.size(), _getOBXPutMode(mode));
  id = _handlePutObjectResult(object, id, newId);
  _builder.resetIfLarge();
  return newId;
}