Skip to content

Commit 4317c53

Browse files
authored
Adopt concurrency adoption guidelines (#230)
Adopt Swift Concurrency adoption guidelines for Swift Server Libraries (swift-server/guides#70). - Use #if compiler(>=5.5) && canImport(_Concurrency) to judge if Concurrency is available - Some clean up
1 parent 39b34a1 commit 4317c53

File tree

12 files changed

+13
-72
lines changed

12 files changed

+13
-72
lines changed

Examples/Deployment/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ The SAM template will provide an output labelled `LambdaApiGatewayEndpoint` whic
8787

8888
```
8989
curl <<LambdaApiGatewayEndpoint>>
90-
```
90+
```
9191

9292
***Warning:*** This SAM template is only intended as a sample and creates a publicly accessible HTTP endpoint.
9393

@@ -162,7 +162,7 @@ For example:
162162

163163
```
164164
curl https://r39lvhfng3.execute-api.us-east-1.amazonaws.com/api
165-
```
165+
```
166166

167167
***Warning:*** This Serverless template is only intended as a sample and creates a publicly accessible HTTP endpoint.
168168

Examples/Deployment/scripts/SAM/APIGateway-template.yml

-30
This file was deleted.

Examples/Deployment/scripts/serverless/APIGateway-template.yml

-28
This file was deleted.

Examples/Deployment/scripts/serverless/Benchmark-template.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ provider:
1212
- logs:CreateLogGroup
1313
- logs:CreateLogStream
1414
- logs:PutLogEvents
15-
Resource: "*"
15+
Resource: "*"
1616

1717
functions:
1818
benchmarkFunction:

Examples/Deployment/scripts/serverless/HelloWorld-template.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ provider:
1212
- logs:CreateLogGroup
1313
- logs:CreateLogStream
1414
- logs:PutLogEvents
15-
Resource: "*"
15+
Resource: "*"
1616

1717
functions:
1818
hello:

Sources/AWSLambdaRuntimeCore/Lambda.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public enum Lambda {
5353
return String(cString: value)
5454
}
5555

56-
#if swift(>=5.5)
56+
#if compiler(>=5.5) && canImport(_Concurrency)
5757
// for testing and internal use
5858
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
5959
internal static func run<Handler: LambdaHandler>(configuration: Configuration = .init(), handlerType: Handler.Type) -> Result<Int, Error> {

Sources/AWSLambdaRuntimeCore/LambdaHandler.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import NIOCore
1717

1818
// MARK: - LambdaHandler
1919

20-
#if compiler(>=5.5)
20+
#if compiler(>=5.5) && canImport(_Concurrency)
2121
/// Strongly typed, processing protocol for a Lambda that takes a user defined `Event` and returns a user defined `Output` async.
2222
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
2323
public protocol LambdaHandler: EventLoopLambdaHandler {

Sources/AWSLambdaTesting/Lambda+Testing.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@
3333
// XCTAssertEqual(result, "echo" + input)
3434
// }
3535

36-
#if swift(>=5.5)
36+
#if compiler(>=5.5) && canImport(_Concurrency)
3737
import AWSLambdaRuntime
38-
import AWSLambdaRuntimeCore
3938
import Dispatch
4039
import Logging
4140
import NIOCore

Tests/AWSLambdaRuntimeCoreTests/LambdaHandlerTest.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import NIOCore
1717
import XCTest
1818

1919
class LambdaHandlerTest: XCTestCase {
20-
#if compiler(>=5.5)
20+
#if compiler(>=5.5) && canImport(_Concurrency)
2121

2222
// MARK: - LambdaHandler
2323

Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift renamed to Tests/AWSLambdaRuntimeTests/Lambda+CodableTest.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class CodableLambdaTest: XCTestCase {
8282
XCTAssertEqual(response?.requestId, request.requestId)
8383
}
8484

85-
#if swift(>=5.5)
85+
#if compiler(>=5.5) && canImport(_Concurrency)
8686
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
8787
func testCodableVoidHandler() {
8888
struct Handler: LambdaHandler {
@@ -183,7 +183,7 @@ private struct Response: Codable, Equatable {
183183
}
184184
}
185185

186-
#if swift(>=5.5)
186+
#if compiler(>=5.5) && canImport(_Concurrency)
187187
// NOTE: workaround until we have async test support on linux
188188
// https://github.com/apple/swift-corelibs-xctest/pull/326
189189
extension XCTestCase {

Tests/AWSLambdaTestingTests/Tests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#if swift(>=5.5)
15+
#if compiler(>=5.5) && canImport(_Concurrency)
1616
import AWSLambdaRuntime
1717
import AWSLambdaTesting
1818
import NIOCore

readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ First, add a dependency on the event packages:
144144

145145
Beyond the small cognitive complexity of using the `EventLoopFuture` based APIs, note these APIs should be used with extra care. An `EventLoopLambdaHandler` will execute the user code on the same `EventLoop` (thread) as the library, making processing faster but requiring the user code to never call blocking APIs as it might prevent the underlying process from functioning.
146146

147-
## Deploying to AWS Lambda
147+
## Deploying to AWS Lambda
148148

149149
To deploy Lambda functions to AWS Lambda, you need to compile the code for Amazon Linux which is the OS used on AWS Lambda microVMs, package it as a Zip file, and upload to AWS.
150150

@@ -160,7 +160,7 @@ The library defines three protocols for the implementation of a Lambda Handler.
160160

161161
### ByteBufferLambdaHandler
162162

163-
An `EventLoopFuture` based processing protocol for a Lambda that takes a `ByteBuffer` and returns a `ByteBuffer?` asynchronously.
163+
An `EventLoopFuture` based processing protocol for a Lambda that takes a `ByteBuffer` and returns a `ByteBuffer?` asynchronously.
164164

165165
`ByteBufferLambdaHandler` is the lowest level protocol designed to power the higher level `EventLoopLambdaHandler` and `LambdaHandler` based APIs. Users are not expected to use this protocol, though some performance sensitive applications that operate at the `ByteBuffer` level or have special serialization needs may choose to do so.
166166

0 commit comments

Comments
 (0)