Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 4363297

Browse files
authored
add guidance on importing
1 parent 5a42e21 commit 4363297

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/concurrency-adoption-guidelines.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ In 2021 we saw structured concurrency and actors arrive with Swift 5.5. Now is a
99

1010
## What you can do right now
1111

12+
### `#if` guarding code using Concurrency
13+
14+
In order to have code using concurrency along with code not using concurrency, you may have to `#if` guard certain pieces of code. The correct way to do so is the following:
15+
16+
```swift
17+
#if compiler(>=5.5) && canImport(_Concurrency)
18+
...
19+
#endif
20+
```
21+
22+
Please note that you do _not_ need to _import_ the `_Concurrency` at all, if it is present it is imported automatically.
23+
24+
```swift
25+
// DO NOT DO THIS.
26+
// Instead don't do any import and it'll import automatically when possible.
27+
#if compiler(>=5.5) && canImport(_Concurrency)
28+
import _Concurrency
29+
#endif
30+
```
31+
32+
33+
1234
### API Design
1335

1436
Firstly, existing libraries should strive to add `async` functions where possible to their user-facing “surface” APIs in addition to existing `*Future` based APIs wherever possible. These additive APIs can be gated on the Swift version and can be added without breaking existing users' code, for example like this:

0 commit comments

Comments
 (0)