@@ -106,7 +106,7 @@ public func run<
106
106
// MARK: - Custom Execution Body
107
107
108
108
/// Run an executable with given parameters and a custom closure
109
- /// to manage the running subprocess' lifetime and stream its standard output .
109
+ /// to manage the running subprocess' lifetime.
110
110
/// - Parameters:
111
111
/// - executable: The executable to run.
112
112
/// - arguments: The arguments to pass to the executable.
@@ -160,6 +160,11 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol, Error: Out
160
160
/// when running the executable.
161
161
/// - input: The input to send to the executable.
162
162
/// - error: How to manager executable standard error.
163
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
164
+ /// from the subprocess's standard error stream. If `nil`, uses the system page size
165
+ /// as the default buffer size. Larger buffer sizes may improve performance for
166
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
167
+ /// may reduce memory usage and improve responsiveness for interactive applications.
163
168
/// - isolation: the isolation context to run the body closure.
164
169
/// - body: The custom execution body to manually control the running process
165
170
/// - Returns an executableResult type containing the return value
@@ -172,6 +177,7 @@ public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
172
177
platformOptions: PlatformOptions = PlatformOptions ( ) ,
173
178
input: Input = . none,
174
179
error: Error = . discarded,
180
+ preferredOutputSize: Int ? = nil ,
175
181
isolation: isolated ( any Actor ) ? = #isolation,
176
182
body: ( ( Execution , AsyncBufferSequence ) async throws -> Result )
177
183
) async throws -> ExecutionResult < Result > where Error. OutputType == Void {
@@ -186,6 +192,7 @@ public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
186
192
configuration,
187
193
input: input,
188
194
error: error,
195
+ preferredBufferSize: preferredOutputSize,
189
196
isolation: isolation,
190
197
body: body
191
198
)
@@ -202,6 +209,11 @@ public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
202
209
/// when running the executable.
203
210
/// - input: The input to send to the executable.
204
211
/// - output: How to manager executable standard output.
212
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
213
+ /// from the subprocess's standard error stream. If `nil`, uses the system page size
214
+ /// as the default buffer size. Larger buffer sizes may improve performance for
215
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
216
+ /// may reduce memory usage and improve responsiveness for interactive applications.
205
217
/// - isolation: the isolation context to run the body closure.
206
218
/// - body: The custom execution body to manually control the running process
207
219
/// - Returns an executableResult type containing the return value
@@ -214,6 +226,7 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
214
226
platformOptions: PlatformOptions = PlatformOptions ( ) ,
215
227
input: Input = . none,
216
228
output: Output ,
229
+ preferredBufferSize: Int ? = nil ,
217
230
isolation: isolated ( any Actor ) ? = #isolation,
218
231
body: ( ( Execution , AsyncBufferSequence ) async throws -> Result )
219
232
) async throws -> ExecutionResult < Result > where Output. OutputType == Void {
@@ -228,6 +241,7 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
228
241
configuration,
229
242
input: input,
230
243
output: output,
244
+ preferredBufferSize: preferredBufferSize,
231
245
isolation: isolation,
232
246
body: body
233
247
)
@@ -244,6 +258,11 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
244
258
/// - platformOptions: The platform specific options to use
245
259
/// when running the executable.
246
260
/// - error: How to manager executable standard error.
261
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
262
+ /// from the subprocess's standard output stream. If `nil`, uses the system page size
263
+ /// as the default buffer size. Larger buffer sizes may improve performance for
264
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
265
+ /// may reduce memory usage and improve responsiveness for interactive applications.
247
266
/// - isolation: the isolation context to run the body closure.
248
267
/// - body: The custom execution body to manually control the running process
249
268
/// - Returns an executableResult type containing the return value
@@ -255,6 +274,7 @@ public func run<Result, Error: OutputProtocol>(
255
274
workingDirectory: FilePath ? = nil ,
256
275
platformOptions: PlatformOptions = PlatformOptions ( ) ,
257
276
error: Error = . discarded,
277
+ preferredBufferSize: Int ? = nil ,
258
278
isolation: isolated ( any Actor ) ? = #isolation,
259
279
body: ( ( Execution , StandardInputWriter , AsyncBufferSequence ) async throws -> Result )
260
280
) async throws -> ExecutionResult < Result > where Error. OutputType == Void {
@@ -268,6 +288,7 @@ public func run<Result, Error: OutputProtocol>(
268
288
return try await run (
269
289
configuration,
270
290
error: error,
291
+ preferredBufferSize: preferredBufferSize,
271
292
isolation: isolation,
272
293
body: body
273
294
)
@@ -284,6 +305,11 @@ public func run<Result, Error: OutputProtocol>(
284
305
/// - platformOptions: The platform specific options to use
285
306
/// when running the executable.
286
307
/// - output: How to manager executable standard output.
308
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
309
+ /// from the subprocess's standard error stream. If `nil`, uses the system page size
310
+ /// as the default buffer size. Larger buffer sizes may improve performance for
311
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
312
+ /// may reduce memory usage and improve responsiveness for interactive applications.
287
313
/// - isolation: the isolation context to run the body closure.
288
314
/// - body: The custom execution body to manually control the running process
289
315
/// - Returns an executableResult type containing the return value
@@ -295,6 +321,7 @@ public func run<Result, Output: OutputProtocol>(
295
321
workingDirectory: FilePath ? = nil ,
296
322
platformOptions: PlatformOptions = PlatformOptions ( ) ,
297
323
output: Output ,
324
+ preferredBufferSize: Int ? = nil ,
298
325
isolation: isolated ( any Actor ) ? = #isolation,
299
326
body: ( ( Execution , StandardInputWriter , AsyncBufferSequence ) async throws -> Result )
300
327
) async throws -> ExecutionResult < Result > where Output. OutputType == Void {
@@ -308,6 +335,7 @@ public func run<Result, Output: OutputProtocol>(
308
335
return try await run (
309
336
configuration,
310
337
output: output,
338
+ preferredBufferSize: preferredBufferSize,
311
339
isolation: isolation,
312
340
body: body
313
341
)
@@ -323,6 +351,11 @@ public func run<Result, Output: OutputProtocol>(
323
351
/// - workingDirectory: The working directory in which to run the executable.
324
352
/// - platformOptions: The platform specific options to use
325
353
/// when running the executable.
354
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
355
+ /// from the subprocess's standard output and error stream. If `nil`, uses the system page size
356
+ /// as the default buffer size. Larger buffer sizes may improve performance for
357
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
358
+ /// may reduce memory usage and improve responsiveness for interactive applications.
326
359
/// - isolation: the isolation context to run the body closure.
327
360
/// - body: The custom execution body to manually control the running process
328
361
/// - Returns an executableResult type containing the return value
@@ -333,6 +366,7 @@ public func run<Result>(
333
366
environment: Environment = . inherit,
334
367
workingDirectory: FilePath ? = nil ,
335
368
platformOptions: PlatformOptions = PlatformOptions ( ) ,
369
+ preferredBufferSize: Int ? = nil ,
336
370
isolation: isolated ( any Actor ) ? = #isolation,
337
371
body: (
338
372
(
@@ -352,6 +386,7 @@ public func run<Result>(
352
386
)
353
387
return try await run (
354
388
configuration,
389
+ preferredBufferSize: preferredBufferSize,
355
390
isolation: isolation,
356
391
body: body
357
392
)
@@ -561,6 +596,11 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol, Error: Out
561
596
/// - configuration: The configuration to run.
562
597
/// - input: The input to send to the executable.
563
598
/// - error: How to manager executable standard error.
599
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
600
+ /// from the subprocess's standard output stream. If `nil`, uses the system page size
601
+ /// as the default buffer size. Larger buffer sizes may improve performance for
602
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
603
+ /// may reduce memory usage and improve responsiveness for interactive applications.
564
604
/// - isolation: the isolation context to run the body closure.
565
605
/// - body: The custom execution body to manually control the running process
566
606
/// - Returns an executableResult type containing the return value
@@ -569,6 +609,7 @@ public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
569
609
_ configuration: Configuration ,
570
610
input: Input = . none,
571
611
error: Error = . discarded,
612
+ preferredBufferSize: Int ? = nil ,
572
613
isolation: isolated ( any Actor ) ? = #isolation,
573
614
body: ( ( Execution , AsyncBufferSequence ) async throws -> Result )
574
615
) async throws -> ExecutionResult < Result > where Error. OutputType == Void {
@@ -594,7 +635,10 @@ public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
594
635
}
595
636
596
637
// Body runs in the same isolation
597
- let outputSequence = AsyncBufferSequence ( diskIO: outputIOBox. take ( ) !. consumeIOChannel ( ) )
638
+ let outputSequence = AsyncBufferSequence (
639
+ diskIO: outputIOBox. take ( ) !. consumeIOChannel ( ) ,
640
+ preferredBufferSize: preferredBufferSize
641
+ )
598
642
let result = try await body ( execution, outputSequence)
599
643
try await group. waitForAll ( )
600
644
return result
@@ -608,6 +652,11 @@ public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
608
652
/// - configuration: The configuration to run.
609
653
/// - input: The input to send to the executable.
610
654
/// - output: How to manager executable standard output.
655
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
656
+ /// from the subprocess's standard error stream. If `nil`, uses the system page size
657
+ /// as the default buffer size. Larger buffer sizes may improve performance for
658
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
659
+ /// may reduce memory usage and improve responsiveness for interactive applications.
611
660
/// - isolation: the isolation context to run the body closure.
612
661
/// - body: The custom execution body to manually control the running process
613
662
/// - Returns an executableResult type containing the return value
@@ -616,6 +665,7 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
616
665
_ configuration: Configuration ,
617
666
input: Input = . none,
618
667
output: Output ,
668
+ preferredBufferSize: Int ? = nil ,
619
669
isolation: isolated ( any Actor ) ? = #isolation,
620
670
body: ( ( Execution , AsyncBufferSequence ) async throws -> Result )
621
671
) async throws -> ExecutionResult < Result > where Output. OutputType == Void {
@@ -641,7 +691,10 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
641
691
}
642
692
643
693
// Body runs in the same isolation
644
- let errorSequence = AsyncBufferSequence ( diskIO: errorIOBox. take ( ) !. consumeIOChannel ( ) )
694
+ let errorSequence = AsyncBufferSequence (
695
+ diskIO: errorIOBox. take ( ) !. consumeIOChannel ( ) ,
696
+ preferredBufferSize: preferredBufferSize
697
+ )
645
698
let result = try await body ( execution, errorSequence)
646
699
try await group. waitForAll ( )
647
700
return result
@@ -655,13 +708,19 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
655
708
/// - Parameters:
656
709
/// - configuration: The `Configuration` to run.
657
710
/// - error: How to manager executable standard error.
711
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
712
+ /// from the subprocess's standard output stream. If `nil`, uses the system page size
713
+ /// as the default buffer size. Larger buffer sizes may improve performance for
714
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
715
+ /// may reduce memory usage and improve responsiveness for interactive applications.
658
716
/// - isolation: the isolation context to run the body closure.
659
717
/// - body: The custom execution body to manually control the running process
660
718
/// - Returns an executableResult type containing the return value
661
719
/// of the closure.
662
720
public func run< Result, Error: OutputProtocol > (
663
721
_ configuration: Configuration ,
664
722
error: Error = . discarded,
723
+ preferredBufferSize: Int ? = nil ,
665
724
isolation: isolated ( any Actor ) ? = #isolation,
666
725
body: ( ( Execution , StandardInputWriter , AsyncBufferSequence ) async throws -> Result )
667
726
) async throws -> ExecutionResult < Result > where Error. OutputType == Void {
@@ -673,7 +732,10 @@ public func run<Result, Error: OutputProtocol>(
673
732
error: try error. createPipe ( )
674
733
) { execution, inputIO, outputIO, errorIO in
675
734
let writer = StandardInputWriter ( diskIO: inputIO!)
676
- let outputSequence = AsyncBufferSequence ( diskIO: outputIO!. consumeIOChannel ( ) )
735
+ let outputSequence = AsyncBufferSequence (
736
+ diskIO: outputIO!. consumeIOChannel ( ) ,
737
+ preferredBufferSize: preferredBufferSize
738
+ )
677
739
return try await body ( execution, writer, outputSequence)
678
740
}
679
741
}
@@ -684,13 +746,19 @@ public func run<Result, Error: OutputProtocol>(
684
746
/// - Parameters:
685
747
/// - configuration: The `Configuration` to run.
686
748
/// - output: How to manager executable standard output.
749
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
750
+ /// from the subprocess's standard error stream. If `nil`, uses the system page size
751
+ /// as the default buffer size. Larger buffer sizes may improve performance for
752
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
753
+ /// may reduce memory usage and improve responsiveness for interactive applications.
687
754
/// - isolation: the isolation context to run the body closure.
688
755
/// - body: The custom execution body to manually control the running process
689
756
/// - Returns an executableResult type containing the return value
690
757
/// of the closure.
691
758
public func run< Result, Output: OutputProtocol > (
692
759
_ configuration: Configuration ,
693
760
output: Output ,
761
+ preferredBufferSize: Int ? = nil ,
694
762
isolation: isolated ( any Actor ) ? = #isolation,
695
763
body: ( ( Execution , StandardInputWriter , AsyncBufferSequence ) async throws -> Result )
696
764
) async throws -> ExecutionResult < Result > where Output. OutputType == Void {
@@ -702,14 +770,24 @@ public func run<Result, Output: OutputProtocol>(
702
770
error: try error. createPipe ( )
703
771
) { execution, inputIO, outputIO, errorIO in
704
772
let writer = StandardInputWriter ( diskIO: inputIO!)
705
- let errorSequence = AsyncBufferSequence ( diskIO: errorIO!. consumeIOChannel ( ) )
773
+ let errorSequence = AsyncBufferSequence (
774
+ diskIO: errorIO!. consumeIOChannel ( ) ,
775
+ preferredBufferSize: preferredBufferSize
776
+ )
706
777
return try await body ( execution, writer, errorSequence)
707
778
}
708
779
}
709
780
710
781
/// Run an executable with given parameters specified by a `Configuration`
782
+ /// and a custom closure to manage the running subprocess' lifetime, write to its
783
+ /// standard input, and stream its standard output and standard error.
711
784
/// - Parameters:
712
785
/// - configuration: The `Subprocess` configuration to run.
786
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
787
+ /// from the subprocess's standard output and error stream. If `nil`, uses the system page size
788
+ /// as the default buffer size. Larger buffer sizes may improve performance for
789
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
790
+ /// may reduce memory usage and improve responsiveness for interactive applications.
713
791
/// - isolation: the isolation context to run the body closure.
714
792
/// - body: The custom configuration body to manually control
715
793
/// the running process, write to its standard input, stream
@@ -718,6 +796,7 @@ public func run<Result, Output: OutputProtocol>(
718
796
/// of the closure.
719
797
public func run< Result> (
720
798
_ configuration: Configuration ,
799
+ preferredBufferSize: Int ? = nil ,
721
800
isolation: isolated ( any Actor ) ? = #isolation,
722
801
body: ( ( Execution , StandardInputWriter , AsyncBufferSequence , AsyncBufferSequence ) async throws -> Result )
723
802
) async throws -> ExecutionResult < Result > {
@@ -730,8 +809,14 @@ public func run<Result>(
730
809
error: try error. createPipe ( )
731
810
) { execution, inputIO, outputIO, errorIO in
732
811
let writer = StandardInputWriter ( diskIO: inputIO!)
733
- let outputSequence = AsyncBufferSequence ( diskIO: outputIO!. consumeIOChannel ( ) )
734
- let errorSequence = AsyncBufferSequence ( diskIO: errorIO!. consumeIOChannel ( ) )
812
+ let outputSequence = AsyncBufferSequence (
813
+ diskIO: outputIO!. consumeIOChannel ( ) ,
814
+ preferredBufferSize: preferredBufferSize
815
+ )
816
+ let errorSequence = AsyncBufferSequence (
817
+ diskIO: errorIO!. consumeIOChannel ( ) ,
818
+ preferredBufferSize: preferredBufferSize
819
+ )
735
820
return try await body ( execution, writer, outputSequence, errorSequence)
736
821
}
737
822
}
0 commit comments