Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conform AnyAsyncSequence to Sendable #44

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yamada-k-25
Copy link

Description

I defined an AsyncPassthroughSubject as a private property and exposed it as an AnyAsyncSequence by performing type erasure with .eraseToAnyAsyncSequence(). For example:

actor SampleActor {
    private let numbersSubject = AsyncPassthroughSubject<Int>()
    public var numbers: AnyAsyncSequence<Int> {
        self.numbersSubject.eraseToAnyAsyncSequence()
    }
    ...
}

I then use this actor to retrieve values from numbers like so:

let sampleActor = SampleActor()

for try await number in await sampleActor.numbers {
    ...
}

However, in my project I am using Swift 6, where the compiler enforces Sendable checking. Since AnyAsyncSequence does not conform to Sendable, the following error occurs:

Non-sendable type 'AnyAsyncSequence<Int>' in implicitly asynchronous access to actor-isolated property 'numbers' cannot cross actor boundary

Although it's possible to work around this issue on the user side (for example, by adding extension AnyAsyncSequence: @unchecked Sendable {} or by marking the property as public nonisolated var numbers: AnyAsyncSequence<Int>), I would like to resolve this problem within the library itself.

Checklist

  • this PR is based on the main branch and is up-to-date, if not please rebase your branch on the top of main
  • the commits inside this PR have explicit commit messages
  • unit tests cover the new feature or the bug fix
  • the feature is documented in the README.md if it makes sense
  • the CHANGELOG is up-to-date

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant