swift-server / swift-aws-lambda-runtime

Swift implementation of AWS Lambda Runtime
Apache License 2.0
1.14k stars 104 forks source link

adoption of sendable #252

Closed tomerd closed 2 years ago

tomerd commented 2 years ago

motivation: adopt to sendable requirments in swift 5.6

changes:

tomerd commented 2 years ago

I think we must not forget to mark LambdaRuntime and LambdaTerminator also as Sendable.

yes, I will merge the terminator PR first than rebase and update

tomerd commented 2 years ago

I think we must not forget to mark LambdaRuntime and LambdaTerminator also as Sendable.

done for LambdaTerminator. why would we want LambdaRuntime to be Sendable? it is not used directly by the users atm afaik.

fabianfett commented 2 years ago

Why would we want LambdaRuntime to be Sendable? it is not used directly by the users atm afaik.

@tomerd LambdaRuntime is supposed to be used by framework developers that wish to integrate with Lambda, since it allows adopters to hook it into their own lifecycle methods. The vapor lambda bridge works this way. For this reason LambdaRuntime is also part of the public API.

LambdaRuntime should be @unchecked Sendable, since it is thread safe by dispatching to the same eventLoop. This is currently not true for the start method, which needs to be fixed with the pattern:

    public func start() -> EventLoopFuture<Void> {
        if self.eventLoop.inEventLoop {
            return self.start0()
        } else {
            return self.flatSubmit { self.start0() }
        }
    }

    private func start0() -> EventLoopFuture<Void> {
        // current start implementation
    }

After that we should have marked everything in the public API as Sendable that needs to be Sendable.