Skip to content

Replace usage of NIOLockedValueBox with Mutex #487

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
//===----------------------------------------------------------------------===//

import Logging
import NIOConcurrencyHelpers
import NIOCore
import Synchronization

#if canImport(FoundationEssentials)
import FoundationEssentials
Expand All @@ -26,8 +26,7 @@ import Foundation
// We don't want to use `NIOLockedValueBox` here anyway. We would love to use Mutex here, but this
// sadly crashes the compiler today.
public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: StreamingLambdaHandler {
// TODO: We want to change this to Mutex as soon as this doesn't crash the Swift compiler on Linux anymore
let handlerMutex: NIOLockedValueBox<Handler?>
let handlerMutex: Mutex<Handler?>
let logger: Logger
let eventLoop: EventLoop

Expand All @@ -36,7 +35,7 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
eventLoop: EventLoop = Lambda.defaultEventLoop,
logger: Logger = Logger(label: "LambdaRuntime")
) {
self.handlerMutex = NIOLockedValueBox(handler)
self.handlerMutex = Mutex(handler)
self.eventLoop = eventLoop

// by setting the log level here, we understand it can not be changed dynamically at runtime
Expand All @@ -49,7 +48,7 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
}

public func run() async throws {
let handler = self.handlerMutex.withLockedValue { handler in
let handler = self.handlerMutex.withLock { handler in
let result = handler
handler = nil
return result
Expand Down
Loading