I am finding very little documentation on swift concurrency - so I'm finding I have to build most of my own async tools, even though they might already exist somewhere.
However - in most cases I need to make four copies of essentially the same function. For instance - suppose I want an actual proper async "run function after a delay of this long" - I end up with
//
// do this after this amount of time
//
public static func after<T>( ms : Int, function : () -> T) async -> T
{
await delay(ms: ms)
return function()
}
//
// do this after this amount of time
//
public static func after<T>( ms : Int, function : () throws -> T) async throws -> T
{
await delay(ms: ms)
return try function()
}
//
// do this after this amount of time
//
public static func after<T>( ms : Int, function : () async -> T) async -> T
{
await delay(ms: ms)
return await function()
}
//
// do this after this amount of time
//
public static func after<T>( ms : Int, function : () async throws -> T) async throws -> T
{
await delay(ms: ms)
return try await function()
}
so I'm wondering if there's any way of saying that in one function instead - basically saying "and it should work with a function with any combination of async/throw"