Skip to content

Latest commit

 

History

History
4 lines (4 loc) · 1.92 KB

File metadata and controls

4 lines (4 loc) · 1.92 KB
  • Task is an instance part of the concurrency framework that allows us to create a concurrent environment from a non-concurrent method, calling methods using async \ await. Didn't get a thing I said? Yeah, I know, that's the technical definition, but think of Tasks as an employee schedule, and the task unit the actual employee. Tasks are used EVERYWHERE throughout concurrency and one KEY aspect of tasks is actually the priority value. Basically, just like in an employee schedule, some tasks will have a higher or a lower priority than others. For example, getting coffee for your cute co-worker Sarah should be of lower priority than fixing a bug that corrupts the entire database everytime a user likes Sarah's post (well, it depends, but you get the idea). A common misconception about tasks priority is that if you set a task with priority .high, that task would finish before a task that has priority set to .low, and, that's not necessarily true. When running Swift code, the management of the tasks is being handled by Swift, so it tries to optimize all of the tasks to its best efforts, and sometimes this optimization actually makes for tasks that have higher priority to finish after tasks that have lower priority.
  • Another great usage of Tasks are Task Groups. This is, just like Async-Let talked before, is useful for executing a whole group of tasks concurrency and wait for their results at the same time. This is better than Async Let because you don't have to hard-code the exact number of async let lines rather than just looping over an array, with the added benefit that the tasks added to a task group can be scheduled in any order you like.