Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `throws` : `async` = `try` : `await` = `rethorws` : `reasync` = `Result<T>` : `Promise<T>`
- ## `throws` : `async` = `try` : `await`
- ```swift
- // Shows an action sheet and makes select one item
- func actionSheet(itemes: [String]) async -> Int { ... }
- // Calls an `async` function in an `async` function
- func foo() async {
- let selectedIndex = await actionSheet([...])
- ...
- }
- // Calls an `async` function outside `async` functions
- func onClick() {
- do {
- let selectedIndex = await actionSheet([...])
- ...
- } defer // does not block
- }
- ```
- ## Asyncronous error handling
- ```swift
- func download(url: URL) async throws -> Data { ... }
- do {
- let data = await try download(url)
- ...
- } catch error {
- ...
- } defer
- ```
- ## `reasync`
- ```swift
- do {
- let r = await [2, 3, 5].map { (x: Int) async -> Int in ... }
- ...
- } defer
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement