today, non-Sendable types with async initializers are totally unusable with actor isolation.
extension SomeActor
{
func f(_ pool:ConnectionPool) async
{
let connection:Connection = await .init(from: pool)
}
}
error: non-sendable type 'Connection' returned by implicitly
asynchronous call to nonisolated function cannot cross actor boundary
i could not think of any ways to re-spell this API (e.g. await pool.makeConnection(), etc.) to get around the problem. there just doesn’t seem to be a way to use a type like Connection anywhere near an actor.
before someone mentions it, yes i am aware this is what SE-0414 is about. but talking about SE-0414 is unhelpful because SE-0414 is not available for use yet, and likely won’t be for quite some time.
there is always the baseline workaround for problems like this:
extension Connection:@unchecked Sendable
{
}
is there anything better than @unchecked Sendable i can do here?