Skip to content

Commit

Permalink
Close WebSocket connections after HTTP server exits (#85)
Browse files Browse the repository at this point in the history
Resolve #7 as described in vapor/vapor#2451.

Additionaly, new formatting is applied with the new version of SwiftFormat.
  • Loading branch information
MaxDesiatov authored Aug 18, 2020
1 parent 610ab94 commit b083cc0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--indent 2
--indentcase false
--trimwhitespace always
--empty tuple
--voidtype tuple
--nospaceoperators ..<,...
--ifdef noindent
--stripunusedargs closure-only
Expand Down
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ disabled_rules:
- operator_whitespace
- nesting
- cyclomatic_complexity
- opening_brace

line_length: 100

Expand Down
3 changes: 2 additions & 1 deletion Sources/SwiftToolchain/FileDownloadDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ final class FileDownloadDelegate: HTTPClientResponseDelegate {
reportHead?(head)

if let totalBytesString = head.headers.first(name: "Content-Length"),
let totalBytes = Int(totalBytesString) {
let totalBytes = Int(totalBytesString)
{
self.totalBytes = totalBytes
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/SwiftToolchain/ToolchainManagement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ extension FileSystem {
if let versionSpec = versionSpec {
if let url = URL(string: versionSpec),
let filename = url.pathComponents.last,
let match = versionRegEx.matchGroups(in: filename).first?.first {
let match = versionRegEx.matchGroups(in: filename).first?.first
{
terminal.logLookup("Inferred swift version: ", match)
return match
} else {
Expand Down
38 changes: 23 additions & 15 deletions Sources/carton/Model/Template.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,23 @@ struct TargetDependency: CustomStringConvertible {
}

extension Template {
static func createPackage(type: PackageType,
fileSystem: FileSystem,
project: Project,
_ terminal: TerminalController) throws {
static func createPackage(
type: PackageType,
fileSystem: FileSystem,
project: Project,
_ terminal: TerminalController
) throws {
try Toolchain(fileSystem, terminal)
.packageInit(name: project.name, type: type, inPlace: project.inPlace)
}

static func createManifest(fileSystem: FileSystem,
project: Project,
dependencies: [PackageDependency] = [],
targetDepencencies: [TargetDependency] = [],
_ terminal: TerminalController) throws {
static func createManifest(
fileSystem: FileSystem,
project: Project,
dependencies: [PackageDependency] = [],
targetDepencencies: [TargetDependency] = [],
_ terminal: TerminalController
) throws {
try fileSystem.writeFileContents(project.path.appending(component: "Package.swift")) {
"""
// swift-tools-version:5.3
Expand Down Expand Up @@ -118,9 +122,11 @@ extension Templates {
struct Basic: Template {
static let description: String = "A simple SwiftWasm project."

static func create(on fileSystem: FileSystem,
project: Project,
_ terminal: TerminalController) throws {
static func create(
on fileSystem: FileSystem,
project: Project,
_ terminal: TerminalController
) throws {
try fileSystem.changeCurrentWorkingDirectory(to: project.path)
try createPackage(type: .executable,
fileSystem: fileSystem,
Expand All @@ -137,9 +143,11 @@ extension Templates {
struct Tokamak: Template {
static let description: String = "A simple Tokamak project."

static func create(on fileSystem: FileSystem,
project: Project,
_ terminal: TerminalController) throws {
static func create(
on fileSystem: FileSystem,
project: Project,
_ terminal: TerminalController
) throws {
try fileSystem.changeCurrentWorkingDirectory(to: project.path)
try createPackage(type: .executable,
fileSystem: fileSystem,
Expand Down
3 changes: 3 additions & 0 deletions Sources/carton/Server/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,8 @@ final class Server {
func run() throws {
defer { app.shutdown() }
try app.run()
for conn in connections {
try conn.close().wait()
}
}
}

0 comments on commit b083cc0

Please sign in to comment.