> For the complete documentation index, see [llms.txt](https://eneskaraosman53.gitbook.io/swiftui/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://eneskaraosman53.gitbook.io/swiftui/combine/untitled.md).

# Perform asynchronous operation

```swift
var dateFormatter: DateFormatter = {
    let formatter = DateFormatter()
    formatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS "
    return formatter
}()

func fetchData(_ seconds: Int) async -> Int {
    try! await Task.sleep(for: .seconds(seconds))
    let timestamp = await dateFormatter.string(from: Date())
    debugPrint("\(timestamp): Task completed in \(seconds) seconds")
    
    return seconds
}
```

Calling Asynchronous Functions in Series

```swift
await fetchData(1)
await fetchData(2)
await fetchData(3)

// Output;
// "2024-01-24 15:18:23.211 : Task completed in 1 seconds"
// "2024-01-24 15:18:25.247 : Task completed in 2 seconds"
// "2024-01-24 15:18:28.320 : Task completed in 3 seconds"
```

Async Functions in Parallel

```swift
async let first = fetchData(1)
async let second = fetchData(1)
async let third = fetchData(1)

let seconds = await [first, second, third]

// Output;
// "2024-01-24 15:19:40.256 : Task completed in 1 seconds"
// "2024-01-24 15:19:40.256 : Task completed in 1 seconds"
// "2024-01-24 15:19:40.256 : Task completed in 1 seconds"
```
