mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-10 22:45:55 +05:45
Both `return` statements where the same, the `else` was just providing a default value to `customerInfoIfSynced`. Because `??` doesn't support an `async` function, we couldn't use that. By using this new operator we can simplify the implementation to a single `return` statement.
26 lines
797 B
Swift
26 lines
797 B
Swift
//
|
|
// Copyright RevenueCat Inc. All Rights Reserved.
|
|
//
|
|
// Licensed under the MIT License (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://opensource.org/licenses/MIT
|
|
//
|
|
// Operators+Extensions.swift
|
|
//
|
|
// Created by Nacho Soto on 5/23/22.
|
|
|
|
infix operator ???
|
|
|
|
/// Equivalent to `??` but allows an `async` default value.
|
|
/// See https://github.com/apple/swift-evolution/blob/main/proposals/0296-async-await.md#future-directions
|
|
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
|
|
func ??? <T>(value: T?, defaultValue: @autoclosure () async throws -> T) async rethrows -> T {
|
|
if let value = value {
|
|
return value
|
|
} else {
|
|
return try await defaultValue()
|
|
}
|
|
}
|