Skip to content

Commit

Permalink
Remove threadPool from HBRequestContext (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler authored Jan 18, 2024
1 parent ccab285 commit 839984c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
6 changes: 0 additions & 6 deletions Sources/Hummingbird/Server/RequestContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Atomics
import Logging
import NIOConcurrencyHelpers
import NIOCore
import NIOPosix
import Tracing

/// Endpoint path storage
Expand Down Expand Up @@ -74,8 +73,6 @@ public struct HBCoreRequestContext: Sendable {
public protocol HBBaseRequestContext: Sendable {
/// Core context
var coreContext: HBCoreRequestContext { get set }
/// Thread Pool
var threadPool: NIOThreadPool { get }
/// Maximum upload size allowed for routes that don't stream the request payload. This
/// limits how much memory would be used for one request
var maxUploadSize: Int { get }
Expand All @@ -88,9 +85,6 @@ extension HBBaseRequestContext {
/// Response encoder
@inlinable
public var responseEncoder: HBResponseEncoder { coreContext.responseEncoder }
/// ThreadPool attached to application
@inlinable
public var threadPool: NIOThreadPool { NIOThreadPool.singleton }
/// ByteBuffer allocator used by request
@inlinable
public var allocator: ByteBufferAllocator { coreContext.allocator }
Expand Down
6 changes: 3 additions & 3 deletions Tests/HummingbirdTests/FileIOTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FileIOTests: XCTestCase {
func testReadFileIO() async throws {
let router = HBRouter()
router.get("test.jpg") { _, context -> HBResponse in
let fileIO = HBFileIO(threadPool: context.threadPool)
let fileIO = HBFileIO(threadPool: .singleton)
let body = try await fileIO.loadFile(path: "test.jpg", context: context)
return .init(status: .ok, headers: [:], body: body)
}
Expand All @@ -49,7 +49,7 @@ class FileIOTests: XCTestCase {
let filename = "testWrite.txt"
let router = HBRouter()
router.put("store") { request, context -> HTTPResponse.Status in
let fileIO = HBFileIO(threadPool: context.threadPool)
let fileIO = HBFileIO(threadPool: .singleton)
try await fileIO.writeFile(contents: request.body, path: filename, context: context)
return .ok
}
Expand All @@ -72,7 +72,7 @@ class FileIOTests: XCTestCase {
let filename = "testWriteLargeFile.txt"
let router = HBRouter()
router.put("store") { request, context -> HTTPResponse.Status in
let fileIO = HBFileIO(threadPool: context.threadPool)
let fileIO = HBFileIO(threadPool: .singleton)
try await fileIO.writeFile(contents: request.body, path: filename, context: context)
return .ok
}
Expand Down

0 comments on commit 839984c

Please sign in to comment.