swiftlang / swift-sdk-generator

Generate Swift SDKs for cross-compilation
Apache License 2.0
183 stars 15 forks source link

Add (async) throwing defer helpers #59

Closed ffried closed 12 months ago

ffried commented 1 year ago

This offers a more generalized solution to the bugs fixed in #55 and #56 by adding a Helpers target that (currently) contains withThrowingDefer and withAsyncThrowingDefer.

Those functions basically do what was previously done manually at each such occasion:

Also, a new withDockerContainer function was added (fixes the swallowed error, which I also fixed in #58).

MaxDesiatov commented 1 year ago

@weissi I'm curious if you have an opinion on this?

FranzBusch commented 1 year ago

FWIW, I have implemented similar methods before but the one difference is that I (and @weissi) have put the deferred closure into an unstructured task Task {}. The reason for this is that often the code in the defer must run but if the task is already cancelled that code will also get cancelled. I haven't looked at the usages here but this might be an important thing to consider.

ffried commented 1 year ago

@FranzBusch That is a very good point! It this case, it does not make things worse (since the previous implementations actually suffered from the same problem), but it's still something worth having a look at.

With these new helper functions, we can at least change it in a central place (vs. having to adjust multiple sites that follow this pattern).

MaxDesiatov commented 1 year ago

@swift-ci test

MaxDesiatov commented 12 months ago

@swift-ci test