-
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathServerChildChannel.swift
More file actions
64 lines (58 loc) · 2.11 KB
/
ServerChildChannel.swift
File metadata and controls
64 lines (58 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//===----------------------------------------------------------------------===//
//
// This source file is part of the Hummingbird server framework project
//
// Copyright (c) 2023 the Hummingbird authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import Logging
import NIOCore
import ServiceLifecycle
public protocol ChildChannelValue: Sendable {
var eventLoop: EventLoop { get }
}
/// HTTPServer child channel setup protocol
public protocol ServerChildChannel: Sendable {
associatedtype Value: ChildChannelValue
/// Setup child channel
/// - Parameters:
/// - channel: Child channel
/// - logger: Logger used during setup
/// - Returns: Object to process input/output on child channel
func setup(channel: Channel, logger: Logger) -> EventLoopFuture<Value>
/// handle messages being passed down the channel pipeline
/// - Parameters:
/// - value: Object to process input/output on child channel
/// - logger: Logger to use while processing messages
func handle(value: Value, logger: Logger) async
}
extension ServerChildChannel {
/// Build existential ``Server`` from existential `ServerChildChannel`
///
/// - Parameters:
/// - configuration: Configuration for server
/// - onServerRunning: Closure to run once server is up and running
/// - eventLoopGroup: EventLoopGroup the server uses
/// - logger: Logger used by server
/// - Returns: Server Service
public func server(
configuration: ServerConfiguration,
onServerRunning: (@Sendable (Channel) async -> Void)? = { _ in },
eventLoopGroup: EventLoopGroup,
logger: Logger
) -> Service {
Server(
childChannelSetup: self,
configuration: configuration,
onServerRunning: onServerRunning,
eventLoopGroup: eventLoopGroup,
logger: logger
)
}
}