@@ -33,12 +33,13 @@ public final class FileDownloadDelegate: HTTPClientResponseDelegate {
33
33
private let io : NonBlockingFileIO
34
34
private let reportHead : ( ( HTTPResponseHead ) -> Void ) ?
35
35
private let reportProgress : ( ( Progress ) -> Void ) ?
36
-
36
+
37
37
private enum ThreadPool {
38
38
case unowned
39
39
// if we own the thread pool we also need to shut it down
40
40
case owned( NIOThreadPool )
41
41
}
42
+
42
43
private let threadPool : ThreadPool
43
44
44
45
private var fileHandleFuture : EventLoopFuture < NIOFileHandle > ?
@@ -62,7 +63,7 @@ public final class FileDownloadDelegate: HTTPClientResponseDelegate {
62
63
) throws {
63
64
try self . init ( path: path, sharedThreadPool: pool, reportHead: reportHead, reportProgress: reportProgress)
64
65
}
65
-
66
+
66
67
/// Initializes a new file download delegate and spawns a new thread for file I/O.
67
68
///
68
69
/// - parameters:
@@ -79,7 +80,7 @@ public final class FileDownloadDelegate: HTTPClientResponseDelegate {
79
80
) throws {
80
81
try self . init ( path: path, sharedThreadPool: nil , reportHead: reportHead, reportProgress: reportProgress)
81
82
}
82
-
83
+
83
84
private init (
84
85
path: String ,
85
86
sharedThreadPool: NIOThreadPool ? ,
@@ -94,15 +95,14 @@ public final class FileDownloadDelegate: HTTPClientResponseDelegate {
94
95
pool = NIOThreadPool ( numberOfThreads: 1 )
95
96
self . threadPool = . owned( pool)
96
97
}
97
-
98
+
98
99
pool. start ( )
99
100
self . io = NonBlockingFileIO ( threadPool: pool)
100
101
self . filePath = path
101
102
102
103
self . reportHead = reportHead
103
104
self . reportProgress = reportProgress
104
105
}
105
-
106
106
107
107
public func didReceiveHead(
108
108
task: HTTPClient . Task < Response > ,
@@ -150,7 +150,7 @@ public final class FileDownloadDelegate: HTTPClientResponseDelegate {
150
150
private func close( fileHandle: NIOFileHandle ) {
151
151
try ! fileHandle. close ( )
152
152
self . fileHandleFuture = nil
153
- switch threadPool {
153
+ switch self . threadPool {
154
154
case . unowned:
155
155
break
156
156
case . owned( let pool) :
@@ -177,7 +177,7 @@ public final class FileDownloadDelegate: HTTPClientResponseDelegate {
177
177
self . finalize ( )
178
178
return self . progress
179
179
}
180
-
180
+
181
181
deinit {
182
182
switch threadPool {
183
183
case . unowned:
0 commit comments