Skip to content

Commit 0566ef5

Browse files
author
Sebastien Stormacq
committed
remove async constraint on push()
1 parent 6d02848 commit 0566ef5

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

Sources/AWSLambdaRuntime/Lambda+LocalServer.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ internal struct LambdaHTTPServer {
272272

273273
// for streaming requests, push a partial head response
274274
if self.isStreamingResponse(requestHead) {
275-
await self.responsePool.push(
275+
self.responsePool.push(
276276
LocalServerResponse(
277277
id: requestId,
278278
status: .ok
@@ -286,7 +286,7 @@ internal struct LambdaHTTPServer {
286286
// if this is a request from a Streaming Lambda Handler,
287287
// stream the response instead of buffering it
288288
if self.isStreamingResponse(requestHead) {
289-
await self.responsePool.push(
289+
self.responsePool.push(
290290
LocalServerResponse(id: requestId, body: body)
291291
)
292292
} else {
@@ -298,7 +298,7 @@ internal struct LambdaHTTPServer {
298298

299299
if self.isStreamingResponse(requestHead) {
300300
// for streaming response, send the final response
301-
await self.responsePool.push(
301+
self.responsePool.push(
302302
LocalServerResponse(id: requestId, final: true)
303303
)
304304
} else {
@@ -391,7 +391,7 @@ internal struct LambdaHTTPServer {
391391

392392
logger.trace("/invoke received invocation, pushing it to the pool and wait for a lambda response")
393393
// detect concurrent invocations of POST and gently decline the requests while we're processing one.
394-
if await !self.invocationPool.push(LocalServerInvocation(requestId: requestId, request: body)) {
394+
if !self.invocationPool.push(LocalServerInvocation(requestId: requestId, request: body)) {
395395
let response = LocalServerResponse(
396396
id: requestId,
397397
status: .badRequest,
@@ -475,7 +475,7 @@ internal struct LambdaHTTPServer {
475475
}
476476
// enqueue the lambda function response to be served as response to the client /invoke
477477
logger.trace("/:requestId/response received response", metadata: ["requestId": "\(requestId)"])
478-
await self.responsePool.push(
478+
self.responsePool.push(
479479
LocalServerResponse(
480480
id: requestId,
481481
status: .accepted,
@@ -506,7 +506,7 @@ internal struct LambdaHTTPServer {
506506
}
507507
// enqueue the lambda function response to be served as response to the client /invoke
508508
logger.trace("/:requestId/response received response", metadata: ["requestId": "\(requestId)"])
509-
await self.responsePool.push(
509+
self.responsePool.push(
510510
LocalServerResponse(
511511
id: requestId,
512512
status: .internalServerError,
@@ -581,7 +581,7 @@ internal struct LambdaHTTPServer {
581581
/// enqueue an element, or give it back immediately to the iterator if it is waiting for an element
582582
/// Returns true when we receive a element and the pool was in "waiting for continuation" state, false otherwise
583583
@discardableResult
584-
public func push(_ invocation: T) async -> Bool {
584+
public func push(_ invocation: T) -> Bool {
585585

586586
// if the iterator is waiting for an element on `next()``, give it to it
587587
// otherwise, enqueue the element

Tests/AWSLambdaRuntimeTests/PoolTests.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ struct PoolTests {
2424
let pool = LambdaHTTPServer.Pool<String>()
2525

2626
// Push values
27-
await pool.push("first")
28-
await pool.push("second")
27+
pool.push("first")
28+
pool.push("second")
2929

3030
// Iterate and verify order
3131
var values = [String]()
@@ -53,7 +53,9 @@ struct PoolTests {
5353
task.cancel()
5454

5555
// This should complete without receiving any values
56-
try await task.value
56+
do {
57+
try await task.value
58+
} catch is CancellationError {} // this might happen depending on the order on which the cancellation is handled
5759
}
5860

5961
@Test
@@ -78,7 +80,7 @@ struct PoolTests {
7880
try await withThrowingTaskGroup(of: Void.self) { group in
7981
for i in 0..<iterations {
8082
group.addTask {
81-
await pool.push(i)
83+
pool.push(i)
8284
}
8385
}
8486
try await group.waitForAll()
@@ -110,7 +112,7 @@ struct PoolTests {
110112
try await Task.sleep(nanoseconds: 100_000_000) // 0.1 seconds
111113

112114
// Push a value
113-
await pool.push(expectedValue)
115+
pool.push(expectedValue)
114116

115117
// Wait for consumer to complete
116118
try await consumer.value
@@ -140,7 +142,7 @@ struct PoolTests {
140142
for p in 0..<producerCount {
141143
group.addTask {
142144
for i in 0..<messagesPerProducer {
143-
await pool.push(p * messagesPerProducer + i)
145+
pool.push(p * messagesPerProducer + i)
144146
}
145147
}
146148
}

0 commit comments

Comments
 (0)