Signal-iOS/SignalServiceKit/Storage/Database/SDSDatabaseStorage/V2/DBTransaction.swift
2024-04-23 15:49:03 -05:00

32 lines
1.3 KiB
Swift

//
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import Foundation
/// Wrapper around `SDSAnyReadTransaction` that allows the generation
/// of a "fake" instance in tests without touching existing code.
///
/// There should only ever be two concrete implementations of this
/// protocol: `SDSDB.ReadTx` and `MockReadTransaction`.
///
/// Users can bridge to `SDSAnyReadTransaction` by using `SDSDB.shimOnlyBridge`;
/// this is made intentionally cumbersome as it should **never** be used in
/// any concrete class and **only** in shim classes that bridge to old-style code.
public protocol DBReadTransaction: AnyObject {}
/// Wrapper around `SDSAnyWriteTransaction` that allows the generation
/// of a "fake" instance in tests without touching existing code.
///
/// There should only ever be two concrete implementations of this
/// protocol: `SDSDB.WriteTx` and `MockWriteTransaction`
///
/// Users can bridge to `SDSAnyWriteTransaction` by using `SDSDB.shimOnlyBridge`;
/// this is made intentionally cumbersome as it should **never** be used in
/// any concrete class and **only** in shim classes that bridge to old-style code.
public protocol DBWriteTransaction: DBReadTransaction {
func addSyncCompletion(_ block: @escaping () -> Void)
func addAsyncCompletion(on scheduler: Scheduler, _ block: @escaping () -> Void)
}