Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Remove NIOCore exports
Use async/await versions of functions
  • Loading branch information
adam-fowler committed Nov 1, 2023
1 parent 622b8f0 commit 715937a
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Hummingbird server framework project
//
// Copyright (c) 2021-2021 the Hummingbird authors
// Copyright (c) 2021-2023 the Hummingbird authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
Expand All @@ -11,7 +11,9 @@
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import HummingbirdCore
import NIOCore

/// Response body streamer which uses an AsyncSequence as its input.
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
Expand Down
3 changes: 2 additions & 1 deletion Sources/Hummingbird/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Hummingbird server framework project
//
// Copyright (c) 2021-2021 the Hummingbird authors
// Copyright (c) 2021-2023 the Hummingbird authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
Expand All @@ -14,6 +14,7 @@

import HummingbirdCore
import Logging
import NIOCore
#if canImport(Network)
import Network
#endif
Expand Down
6 changes: 1 addition & 5 deletions Sources/Hummingbird/Exports.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Hummingbird server framework project
//
// Copyright (c) 2021-2021 the Hummingbird authors
// Copyright (c) 2021-2023 the Hummingbird authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
Expand All @@ -26,11 +26,7 @@

@_exported import struct NIOCore.ByteBuffer
@_exported import struct NIOCore.ByteBufferAllocator
@_exported import protocol NIOCore.EventLoop
@_exported import class NIOCore.EventLoopFuture
@_exported import protocol NIOCore.EventLoopGroup
@_exported import enum NIOCore.SocketAddress
@_exported import struct NIOCore.TimeAmount

@_exported import struct NIOHTTP1.HTTPHeaders
@_exported import enum NIOHTTP1.HTTPMethod
Expand Down
9 changes: 4 additions & 5 deletions Sources/Hummingbird/Router/RouterMethods.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Hummingbird server framework project
//
// Copyright (c) 2021-2021 the Hummingbird authors
// Copyright (c) 2021-2023 the Hummingbird authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
Expand Down Expand Up @@ -44,7 +44,7 @@ public protocol HBRouterMethods {
}

extension HBRouterMethods {
/// GET path for async closure returning type conforming to ResponseEncodable
/// GET path for async closure returning type conforming to ResponseEncodable
@discardableResult public func get<Output: HBResponseGenerator>(
_ path: String = "",
options: HBRouterMethodOptions = [],
Expand Down Expand Up @@ -118,9 +118,8 @@ extension HBRouterMethods {
return try await _respond(request: request, context: context)
} else {
let buffer = try await request.body.consumeBody(
maxSize: context.applicationContext.configuration.maxUploadSize,
on: context.eventLoop
).get()
maxSize: context.applicationContext.configuration.maxUploadSize
)
var request = request
request.body = .byteBuffer(buffer)
return try await _respond(request: request, context: context)
Expand Down
6 changes: 3 additions & 3 deletions Sources/Hummingbird/Server/RequestContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Hummingbird server framework project
//
// Copyright (c) 2021-2022 the Hummingbird authors
// Copyright (c) 2021-2023 the Hummingbird authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
Expand All @@ -14,8 +14,8 @@

import Atomics
import Logging
import NIOCore
import NIOConcurrencyHelpers
import NIOCore
import Tracing

/// Endpoint path storage
Expand All @@ -26,7 +26,7 @@ public struct EndpointPath: Sendable {

/// Endpoint path
public internal(set) var value: String? {
get { self._value.withLockedValue{ $0 } }
get { self._value.withLockedValue { $0 } }
nonmutating set { self._value.withLockedValue { $0 = newValue } }
}

Expand Down
3 changes: 1 addition & 2 deletions Sources/Hummingbird/Storage/MemoryPersistDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Hummingbird server framework project
//
// Copyright (c) 2021-2021 the Hummingbird authors
// Copyright (c) 2021-2023 the Hummingbird authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
Expand Down Expand Up @@ -69,7 +69,6 @@ public actor HBMemoryPersistDriver<C: Clock>: HBPersistDriver where C.Duration =
}

public func run() async throws {
let cancelled = ManagedAtomic(false)
let timerSequence = AsyncTimerSequence(interval: .seconds(600), clock: .suspending)
.cancelOnGracefulShutdown()
for try await _ in timerSequence {
Expand Down
22 changes: 11 additions & 11 deletions Tests/HummingbirdTests/ApplicationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Hummingbird server framework project
//
// Copyright (c) 2021-2021 the Hummingbird authors
// Copyright (c) 2021-2023 the Hummingbird authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
Expand All @@ -15,6 +15,7 @@
import Atomics
import Hummingbird
import HummingbirdXCT
import NIOCore
import NIOHTTP1
import XCTest

Expand Down Expand Up @@ -194,7 +195,7 @@ final class ApplicationTests: XCTestCase {

func testEventLoopFutureArray() async throws {
let router = HBRouterBuilder(context: HBTestRouterContext.self)
router.patch("array") { _, context -> [String] in
router.patch("array") { _, _ -> [String] in
return ["yes", "no"]
}
let app = HBApplication(responder: router.buildResponder())
Expand Down Expand Up @@ -245,16 +246,15 @@ final class ApplicationTests: XCTestCase {
}
return HBResponse(status: .ok, headers: [:], body: .stream(RequestStreamer(stream: stream)))
}
router.post("size", options: .streamBody) { request, context -> String in
router.post("size", options: .streamBody) { request, _ -> String in
guard let stream = request.body.stream else {
throw HBHTTPError(.badRequest)
}
let size = ManagedAtomic(0)
_ = try await stream.consumeAll(on: context.eventLoop) { buffer in
size.wrappingIncrement(by: buffer.readableBytes, ordering: .relaxed)
return context.success(())
}.get()
return size.load(ordering: .relaxed).description
var size = 0
for try await buffer in stream.sequence {
size += buffer.readableBytes
}
return size.description
}
let app = HBApplication(responder: router.buildResponder())

Expand Down Expand Up @@ -358,7 +358,7 @@ final class ApplicationTests: XCTestCase {
let router = HBRouterBuilder(context: HBTestRouterContext.self)
router
.group("/echo-body")
.post { request, context -> ByteBuffer? in
.post { request, _ -> ByteBuffer? in
return request.body.buffer
}
let app = HBApplication(responder: router.buildResponder())
Expand Down Expand Up @@ -450,7 +450,7 @@ final class ApplicationTests: XCTestCase {

func testTypedResponseFuture() async throws {
let router = HBRouterBuilder(context: HBTestRouterContext.self)
router.delete("/hello") { _, context in
router.delete("/hello") { _, _ in
HBEditedResponse(
status: .imATeapot,
headers: ["test": "value", "content-type": "application/json"],
Expand Down
3 changes: 2 additions & 1 deletion Tests/HummingbirdTests/RouterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Atomics
@testable import Hummingbird
import HummingbirdXCT
import Logging
import NIOCore
import Tracing
import XCTest

Expand Down Expand Up @@ -218,7 +219,7 @@ final class RouterTests: XCTestCase {
.group("/test")
.add(middleware: TestMiddleware())
.group("/group")
.get { _, context in
.get { _, _ in
return "hello"
}
let app = HBApplication(responder: router.buildResponder())
Expand Down

0 comments on commit 715937a

Please sign in to comment.