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.

For typical use cases, use putAsync instead which supports objects with relations. Use this when a large number of puts needs to be performed in parallel (e.g. this is called many times) for better performance.

To wait on the completion of submitted operations, use Store.awaitQueueSubmitted or Store.awaitQueueCompletion.

The actual database put operation may fail even if this returned normally (and even if a new ID for a new object was returned), for example due to a unique constraint violation. So do not rely on the object being put or add checks as necessary.

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

See also putAsync which supports relations and returns a Future that only completes after a put was successful.

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;
}