upload method

Future<List<DataValueSet>?> upload(
  1. dynamic callback(
    1. RequestProgress,
    2. bool
    ), {
  2. Dio? dioTestClient,
})

Implementation

Future<List<DataValueSet>?> upload(Function(RequestProgress, bool) callback,
    {Dio? dioTestClient}) async {
  List<DataValueSet> dataValueSets = await this
      .where(attribute: 'synced', value: false)
      .where(attribute: 'dirty', value: true)
      .withDataValues()
      .get();

  List<String> dataValueSetIds = [];

  final queue = Queue(parallel: 50);
  num availableItemCount = 0;

  dataValueSets.forEach((dataValueSet) {
    dataValueSetIds.add(dataValueSet.id as String);
    availableItemCount++;
    queue.add(
        () => this.uploadOne(dataValueSet, dioTestClient: dioTestClient));
  });

  if (availableItemCount == 0) {
    queue.cancel();
  } else {
    await queue.onComplete;
  }

  return await DataValueSetQuery(database: database)
      .byIds(dataValueSetIds)
      .get();
}