Skip to content

How to use @Dependency on Codable types: "does not conform to protocol 'Decodable'" #283

Answered by mbrandonw
finestructure asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @finestructure, ok I think I see the problem. It isn't the unstructured task, those specifically do inherit task locals (only Task.detached does not).

However, escaping closures lose dependencies. So by the time you get inside transaction { … } you have lost your dependencies, and similarly for makeFutureWithTask { … }. In general, escaping closures are the enemy of structured programming, and so therefore also the enemy of task locals or any of the tools in structured concurrency.

Luckily we do have a tool for this though. You can use withEscapedDependencies to escape dependencies in order to propagate them into an escaping closure:

static func analyze(database: Database, repository: R…

Replies: 1 comment 12 replies

Comment options

You must be logged in to vote
12 replies
@mbrandonw
Comment options

@finestructure
Comment options

@finestructure
Comment options

@mbrandonw
Comment options

Answer selected by finestructure
@finestructure
Comment options

@finestructure
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants