Use async let when comparing two expressions
KaiOelfke opened this issue · comments
Some expect functions take two expressions and compare the results. Would it not make sense to use async let here instead of waiting for the first expression to complete before executing the second expression?
public func expectEqual<T: Equatable>(timeout: TimeInterval = 1,
_ expression1: @escaping () async throws -> T,
_ expression2: @escaping () async throws -> T,
file: StaticString = #file,
line: UInt = #line) async throws {
let expression = {
async let first = expression1()
async let second = expression2()
return try await first == second
}
if try await !evaluate(expression, timeout: timeout) {
async let first = expression1()
async let second = expression2()
try await failExpectEqual(first: first, second: second, file: file, line: line)
}
}
Definitely! Something you want contribute with? Otherwise I'll add it to the backlog.
I can make a PR when I have time.