Using dependencies with async let
#325
finestructure
started this conversation in
Show and tell
Replies: 1 comment
-
@finestructure @Dependency(\.github) var _github
let github = _github
async let metadata = try await github.fetchMetadata(owner, repository)
async let license = await github.fetchLicense(owner, repository) I wonder if this is worth bringing up on the Swift forums. If folks have an idea of how we could make things play more nicely, we're all ears! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I ran into a problem using a dependency with
async let
. It took me a moment to discover the (I think) proper way of dealing with this and so I thought I'd share my solution in case it might help others in the same situation.I was transitioning code like the following (using the "old"
Current
-based dependency injection style):to the new
@Dependency
style:Turns out this doesn't actually work in Swift 6 language mode. It fails to compile with:
and that makes sense if you think about it. Under the hood,
async let
is aTask
and we're sharinggithub
into two differentTask
s here.At first I came up with a clumsy workaround:
but then I realised that I can simply be more surgical with the dependency variables:
Hope that helps!
Beta Was this translation helpful? Give feedback.
All reactions