Skip to content

Commit

Permalink
Merge pull request #1 from ktoso/patch-6
Browse files Browse the repository at this point in the history
Fix some code snippets in NNNN-nonisolated-for-global-actor-cutoff.md
  • Loading branch information
simanerush committed Sep 11, 2024
2 parents 968e64c + 141d839 commit 1bfd491
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions proposals/NNNN-nonisolated-for-global-actor-cutoff.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ In the above code, `S` can still conform to the globally-isolated protocol `P` w
However, the above method would not work for cutting off the global isolation inference on a protocol itself. There is a very nonobvious workaround: when the compiler is inferring global actor isolation, if there are multiple inference sources with conflicting global actors, no global actor is inferred. This is demonstrated by the following example:

```swift
class FakeExecutor: FakeGlobalActor {
final class FakeExecutor: SerialExecutor {
static let shared: FakeExecutor = .init()

func enqueue(_ job: consuming ExecutorJob) {
Expand All @@ -65,15 +65,15 @@ public actor FakeGlobalActor: Sendable {

private init() {}
public nonisolated var unownedExecutor: UnownedSerialExecutor {
FakeGlobalActor.shared.asUnownedSerialExecutor()
FakeExecutor.shared.asUnownedSerialExecutor()
}
}

@MainActor
protocol GloballyIsolated {}

@FakeGlobalActor
protocol RemoveGlobalActor
protocol RemoveGlobalActor {}

protocol RefinedProtocol: GloballyIsolated, RemoveGlobalActor {} // 'RefinedProtocol' is non-isolated
```
Expand Down

0 comments on commit 1bfd491

Please sign in to comment.