Call to main actor-isolated instance method XXX in a synchronous nonisolated context

This is bug in current swift versions as compiler is not able to recognize the global actor context for a defer block, the discussion for this is going on swift forum and a PR with fix also available that should resolve this issue in future swift versions. For now, explicitly global actor context need to … Read more

Difference of using async / await vs promises?

async/await and promises are closely related. async functions return promises, and await is syntactic sugar for waiting for a promise to be resolved. The only drawback from having a mix of promises and async functions might be readability and maintainability of the code, but you can certainly use the return value of async functions as … Read more

Why exactly is async void considered bad practice?

Well, walking through the reasons in the “avoid async void” article: Async void methods have different error-handling semantics. Exceptions escaping from PrimeCustomTask will be very awkward to handle. Async void methods have different composing semantics. This is an argument centered around code maintainability and reuse. Essentially, the logic in PrimeCustomTask is there and that’s it … Read more

Return multiple values from a C# asynchronous method

After playing with the code I was able to figure it out. Here is the solution. public async Task DeleteSchoolTask(int schoolNumber, int taskDetailId) { var result = await GetTaskTypeAndId(taskDetailId); int taskId = result.Item1; string taskType = result.Item2; // step 1: delete attachment physically from server var fileService = new FileService(Logger, CurrentUser); var relativeFilePath = $”{schoolNumber}\\{Consts.RM_SCHOOL}\\{taskDetailId}”; … Read more

Return IAsyncEnumerable from an async method

The struct approach wouldn’t work. If you want to asynchronously return an IAsyncEnumerator<T> value, you could use Task<IAsyncEnumerator<T>> with return Bar();. However, that would be unusual. It would be much more natural to create a new IAsyncEnumerator<T> that incorporates await SomeAsyncMethod() at the beginning of the asynchronous enumerable. To do this, you should use await … Read more