This is odd to me as well. I thought maybe it had to do with evaluateJavaScript
being isolated to @MainActor. Makes sense because results of evaluateJavaScript() are not guaranteed to be Sendable.
But even when we isolated the Task closure to @MainActor
it also does not work.
So then I thought maybe we need to isolate the whole function (see below)
@MainActor func asyncLetErrorOnMainActor() async throws {
async let urlObject = self.webView.evaluateJavaScript("document.location.href")
async let titleObject = self.webView.evaluateJavaScript("document.title")
print(try await urlObject)
print(try await titleObject)
}
I suppose it has to do with how async let
is implemented that I just don't understand where it is crossing the boundaries.
I looked at the following posts
(1) Returning non-Sendable object across actor boundaries via sending keyword
(3) Why does `async let` discern "the origin" of its right expression?
To better understand why a value that comes from an @MainActor isolated function within an @MainActor isolated function/closure throws an error. And I couldn't figure it out.
Is this just an bug?