So, is AsyncStream Sendable or not?

so, AsyncStream is not supposed to be Sendable, yet it compiles as if it were:

class C 
{
    var x:Int
    
    init()
    {
        self.x = 0
    }
}
actor A 
{
    init() 
    {
    }
    
    func foo(_ x:AsyncStream<Int>) async 
    {
        for await y:Int in x
        {
            print(y)
        }
    }
    func bar(_:C) 
    {
    }
}
@main 
enum Main 
{
    static
    func main() async 
    {
        let a:A = .init()
        let c:C = .init()
        let stream:AsyncStream<Int> = .init 
        {
            (continuation:AsyncStream<Int>.Continuation) in 
            
            ...
        }
        
        await a.foo(stream)
        await a.bar(c)
    }
}
$ swiftc -parse-as-library concurrency-boundaries.swift
concurrency-boundaries.swift:53:17: warning: cannot pass argument of non-sendable type 'C' across actors
        await a.bar(c)
                ^
concurrency-boundaries.swift:1:7: note: class 'C' does not conform to the 'Sendable' protocol
class C 

is this a bug, or intended behavior?

Terms of Service

Privacy Policy

Cookie Policy