askarSessionFetch function

Future<AskarResult<EntryListHandle>> askarSessionFetch(
  1. SessionHandle handle,
  2. String category,
  3. String name,
  4. bool forUpdate,
)

Implementation

Future<AskarResult<EntryListHandle>> askarSessionFetch(
  SessionHandle handle,
  String category,
  String name,
  bool forUpdate,
) async {
  Pointer<Utf8> categoryPointer = nullptr;
  Pointer<Utf8> namePointer = nullptr;

  try {
    categoryPointer = category.toNativeUtf8();
    namePointer = name.toNativeUtf8();

    final callback = newCallbackWithHandle();

    final initialResult = nativeAskarSessionFetch(
      handle.toInt(),
      categoryPointer,
      namePointer,
      boolToInt(forUpdate),
      callback.nativeCallable.nativeFunction,
      callback.id,
    );

    final callbackResult = await callback.handleResult(initialResult);

    if (callbackResult.errorCode == ErrorCode.success && callbackResult.value == 0) {
      throw Exception(
        "Invalid handle. This means that the function call succeeded but none was found.",
      );
    }

    return AskarResult<EntryListHandle>(
      callbackResult.errorCode,
      EntryListHandle(callbackResult.value),
    );
  } finally {
    freePointer(categoryPointer);
    freePointer(namePointer);
  }
}