This is the updated Pitch [Pitch] @Concurrent macro - #16 by EngOmarElsayed
Macro SPM: [Pitch] @Concurrent macro - #21 by EngOmarElsayed
Hey
everyone,
I started to adopt strict concurrency in my apps and at work. One of the most used annotations for me is @concurrent because all the apps I work on have some kind of heavy processing that should be executed on the background executor, something like network calls for example.
For example:
final class RemoteDataSource {
@concurrent func fetch() async {}
}
I want all the functions in the RemoteDataSource to have the @concurrent to make sure all of them will be executed on the background executor, but there is no way to tell the compiler that all the functions in RemoteDataSource should have @concurrent.
I have to add it manually for every function I create which opens the door for errors and mistakes because I can easily forget it.
So I created a @Concurrent macro that does that for me and I wanted to propose it to be added to the Swift language. The @Concurrent macro can be added to extensions, classes, structs, enums and actors (still thinking about if it should be added to actors but I think it doesn't make sense, I want to see what you think), what it does is simple, it adds @concurrent to all the functions inside that declaration for example:
@Concurrent
final class RemoteDataSource {
// @concurrent this will be added to function by the macro
func fetch() async {}
}
struct FetchDataUseCase {
//....
}
@Concurrent
extension FetchDataUseCase {
// macro will add @concurrent to the functions in this extension only
func fetch() async {}
}
This is a simple syntax sugar to add to the language but could make a difference and make things easier for developers.
What do you think? Especially about the Actor part. Excited to write the proposal for this one ![]()