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

Drop sync and closure APIs #222

Merged
merged 10 commits into from
Aug 24, 2021

Conversation

fabianfett
Copy link
Member

Fixes #212.

Motivation:

For 1.0 we want to have an API that we are happy with going forward. Everything we are not 100% happy with should go out before 1.0. With the release of Swift 5.5, we don't want to have callback based APIs anymore. For this reason we drop support for callback based APIs with this PR.

This also includes the way we deal with Lambda lifecycle: We drop the API's in which a user could create a Handler themselves and pass it to Lambda. The Handler creation is now always a part of the Lambda's lifecycle. For advanced users (users who wish to implement bridges to server frameworks) the advanced Lambda.Lifecycle API will stay.

Modifications:

  • drop callback based LambdaHandler
  • rename AsyncLambdaHandler to LambdaHandler
  • remove synchronous factory methods

Result:

Smaller, cleaner API for 1.0.

@fabianfett fabianfett requested a review from tomerd August 19, 2021 18:11
@fabianfett fabianfett marked this pull request as ready for review August 19, 2021 18:11
logger: Logger,
eventLoop: EventLoop,
allocator: ByteBufferAllocator) {
public init(requestID: String,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomerd We probably need to discuss this one! Maybe we want to add a __forTest_Only() helper method instead of the public initializer.

public static func test<In: Decodable>(
_ closure: @escaping Lambda.CodableVoidClosure<In>,
with event: In,
public static func test<Handler: LambdaHandler>(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomerd Lambda.test only supports new async/await lambdas:

XCTAssertNoThrow(result = try Lambda.test(MyLambda.self, with: input))

The benefit is that the Lambda goes through the complete lifecycle with this approach. Initializer and handler are called.

@@ -36,7 +36,7 @@ extension Lambda {
/// `ByteBufferAllocator` to allocate `ByteBuffer`
public let allocator: ByteBufferAllocator

internal init(logger: Logger, eventLoop: EventLoop, allocator: ByteBufferAllocator) {
public init(logger: Logger, eventLoop: EventLoop, allocator: ByteBufferAllocator) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomerd We probably need to discuss this one! Maybe we want to add a __forTest_Only() helper method instead of the public initializer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this not ideal. why is it needed?

// XCTAssertEqual(result, "echo" + input)
// }

#if DEBUG
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removal intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES

@@ -35,7 +35,7 @@ struct Handler: EventLoopLambdaHandler {
}
}

Lambda.run(Handler())
Lambda.run { $0.eventLoop.makeSucceededFuture(Handler()) }
Copy link
Contributor

@tomerd tomerd Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is kind of meh, we can potentially also support an API that returns an instance and then wraps in successful future to avoid pushing this to the user side

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will readd with a separate PR.

@@ -78,27 +54,19 @@ public enum Lambda {
return String(cString: value)
}

#if swift(>=5.5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just require 5.5? feels wrong to drop support for closures and support < 5.5

Copy link
Member Author

@fabianfett fabianfett Aug 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about this last time. We wanted to stay with 5.2 to allow existing frameworks (Vapor, Noze, Hummingbird, Smoke, and friends) to integrate with Lambda without needing to bump their requirements. For integration into those frameworks developers will nearly always use the Lambda.Lifecycle APIs.

Normal Lambda users should require 5.5 and just use the async APIs.

I guess with this we will do what most of the Swift Server ecosystem is going todo... Make async/await the normal, leave escape hatch for advanced use cases using futures.

@tomerd tomerd merged commit 454fe2e into swift-server:main Aug 24, 2021
@fabianfett fabianfett deleted the ff-drop-sync-and-closure-api branch August 24, 2021 21:20
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.

Remove callback based LambdaHandler
2 participants