@@ -156,6 +156,11 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol, Error: Out
156
156
/// - platformOptions: The platform-specific options to use when running the executable.
157
157
/// - input: The input to send to the executable.
158
158
/// - error: How to manage executable standard error.
159
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
160
+ /// from the subprocess's standard error stream. If `nil`, uses the system page size
161
+ /// as the default buffer size. Larger buffer sizes may improve performance for
162
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
163
+ /// may reduce memory usage and improve responsiveness for interactive applications.
159
164
/// - isolation: the isolation context to run the body closure.
160
165
/// - body: The custom execution body to manually control the running process.
161
166
/// - Returns: an `ExecutableResult` type containing the return value of the closure.
@@ -167,6 +172,7 @@ public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
167
172
platformOptions: PlatformOptions = PlatformOptions ( ) ,
168
173
input: Input = . none,
169
174
error: Error = . discarded,
175
+ preferredBufferSize: Int ? = nil ,
170
176
isolation: isolated ( any Actor ) ? = #isolation,
171
177
body: ( ( Execution , AsyncBufferSequence ) async throws -> Result )
172
178
) async throws -> ExecutionResult < Result > where Error. OutputType == Void {
@@ -181,6 +187,7 @@ public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
181
187
configuration,
182
188
input: input,
183
189
error: error,
190
+ preferredBufferSize: preferredBufferSize,
184
191
isolation: isolation,
185
192
body: body
186
193
)
@@ -196,7 +203,12 @@ public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
196
203
/// - platformOptions: The platform-specific options to use when running the executable.
197
204
/// - input: The input to send to the executable.
198
205
/// - output: How to manage executable standard output.
199
- /// - isolation: The isolation context to run the body closure.
206
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
207
+ /// from the subprocess's standard error stream. If `nil`, uses the system page size
208
+ /// as the default buffer size. Larger buffer sizes may improve performance for
209
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
210
+ /// may reduce memory usage and improve responsiveness for interactive applications.
211
+ /// - isolation: the isolation context to run the body closure.
200
212
/// - body: The custom execution body to manually control the running process
201
213
/// - Returns: an `ExecutableResult` type containing the return value of the closure.
202
214
public func run< Result, Input: InputProtocol , Output: OutputProtocol > (
@@ -207,6 +219,7 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
207
219
platformOptions: PlatformOptions = PlatformOptions ( ) ,
208
220
input: Input = . none,
209
221
output: Output ,
222
+ preferredBufferSize: Int ? = nil ,
210
223
isolation: isolated ( any Actor ) ? = #isolation,
211
224
body: ( ( Execution , AsyncBufferSequence ) async throws -> Result )
212
225
) async throws -> ExecutionResult < Result > where Output. OutputType == Void {
@@ -221,6 +234,7 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
221
234
configuration,
222
235
input: input,
223
236
output: output,
237
+ preferredBufferSize: preferredBufferSize,
224
238
isolation: isolation,
225
239
body: body
226
240
)
@@ -235,6 +249,11 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
235
249
/// - workingDirectory: The working directory in which to run the executable.
236
250
/// - platformOptions: The platform-specific options to use when running the executable.
237
251
/// - error: How to manage executable standard error.
252
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
253
+ /// from the subprocess's standard output stream. If `nil`, uses the system page size
254
+ /// as the default buffer size. Larger buffer sizes may improve performance for
255
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
256
+ /// may reduce memory usage and improve responsiveness for interactive applications.
238
257
/// - isolation: the isolation context to run the body closure.
239
258
/// - body: The custom execution body to manually control the running process
240
259
/// - Returns: An `ExecutableResult` type containing the return value of the closure.
@@ -245,6 +264,7 @@ public func run<Result, Error: OutputProtocol>(
245
264
workingDirectory: FilePath ? = nil ,
246
265
platformOptions: PlatformOptions = PlatformOptions ( ) ,
247
266
error: Error = . discarded,
267
+ preferredBufferSize: Int ? = nil ,
248
268
isolation: isolated ( any Actor ) ? = #isolation,
249
269
body: ( ( Execution , StandardInputWriter , AsyncBufferSequence ) async throws -> Result )
250
270
) async throws -> ExecutionResult < Result > where Error. OutputType == Void {
@@ -258,6 +278,7 @@ public func run<Result, Error: OutputProtocol>(
258
278
return try await run (
259
279
configuration,
260
280
error: error,
281
+ preferredBufferSize: preferredBufferSize,
261
282
isolation: isolation,
262
283
body: body
263
284
)
@@ -272,6 +293,11 @@ public func run<Result, Error: OutputProtocol>(
272
293
/// - workingDirectory: The working directory in which to run the executable.
273
294
/// - platformOptions: The platform-specific options to use when running the executable.
274
295
/// - output: How to manage executable standard output.
296
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
297
+ /// from the subprocess's standard error stream. If `nil`, uses the system page size
298
+ /// as the default buffer size. Larger buffer sizes may improve performance for
299
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
300
+ /// may reduce memory usage and improve responsiveness for interactive applications.
275
301
/// - isolation: the isolation context to run the body closure.
276
302
/// - body: The custom execution body to manually control the running process
277
303
/// - Returns: An `ExecutableResult` type containing the return value of the closure.
@@ -282,6 +308,7 @@ public func run<Result, Output: OutputProtocol>(
282
308
workingDirectory: FilePath ? = nil ,
283
309
platformOptions: PlatformOptions = PlatformOptions ( ) ,
284
310
output: Output ,
311
+ preferredBufferSize: Int ? = nil ,
285
312
isolation: isolated ( any Actor ) ? = #isolation,
286
313
body: ( ( Execution , StandardInputWriter , AsyncBufferSequence ) async throws -> Result )
287
314
) async throws -> ExecutionResult < Result > where Output. OutputType == Void {
@@ -295,6 +322,7 @@ public func run<Result, Output: OutputProtocol>(
295
322
return try await run (
296
323
configuration,
297
324
output: output,
325
+ preferredBufferSize: preferredBufferSize,
298
326
isolation: isolation,
299
327
body: body
300
328
)
@@ -309,6 +337,11 @@ public func run<Result, Output: OutputProtocol>(
309
337
/// - environment: The environment in which to run the executable.
310
338
/// - workingDirectory: The working directory in which to run the executable.
311
339
/// - platformOptions: The platform-specific options to use when running the executable.
340
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
341
+ /// from the subprocess's standard output and error stream. If `nil`, uses the system page size
342
+ /// as the default buffer size. Larger buffer sizes may improve performance for
343
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
344
+ /// may reduce memory usage and improve responsiveness for interactive applications.
312
345
/// - isolation: the isolation context to run the body closure.
313
346
/// - body: The custom execution body to manually control the running process
314
347
/// - Returns: an `ExecutableResult` type containing the return value of the closure.
@@ -318,6 +351,7 @@ public func run<Result>(
318
351
environment: Environment = . inherit,
319
352
workingDirectory: FilePath ? = nil ,
320
353
platformOptions: PlatformOptions = PlatformOptions ( ) ,
354
+ preferredBufferSize: Int ? = nil ,
321
355
isolation: isolated ( any Actor ) ? = #isolation,
322
356
body: (
323
357
(
@@ -337,6 +371,7 @@ public func run<Result>(
337
371
)
338
372
return try await run (
339
373
configuration,
374
+ preferredBufferSize: preferredBufferSize,
340
375
isolation: isolation,
341
376
body: body
342
377
)
@@ -546,6 +581,11 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol, Error: Out
546
581
/// - configuration: The configuration to run.
547
582
/// - input: The input to send to the executable.
548
583
/// - error: How to manager executable standard error.
584
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
585
+ /// from the subprocess's standard output stream. If `nil`, uses the system page size
586
+ /// as the default buffer size. Larger buffer sizes may improve performance for
587
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
588
+ /// may reduce memory usage and improve responsiveness for interactive applications.
549
589
/// - isolation: the isolation context to run the body closure.
550
590
/// - body: The custom execution body to manually control the running process
551
591
/// - Returns an executableResult type containing the return value
@@ -554,6 +594,7 @@ public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
554
594
_ configuration: Configuration ,
555
595
input: Input = . none,
556
596
error: Error = . discarded,
597
+ preferredBufferSize: Int ? = nil ,
557
598
isolation: isolated ( any Actor ) ? = #isolation,
558
599
body: ( ( Execution , AsyncBufferSequence ) async throws -> Result )
559
600
) async throws -> ExecutionResult < Result > where Error. OutputType == Void {
@@ -579,7 +620,10 @@ public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
579
620
}
580
621
581
622
// Body runs in the same isolation
582
- let outputSequence = AsyncBufferSequence ( diskIO: outputIOBox. take ( ) !. consumeIOChannel ( ) )
623
+ let outputSequence = AsyncBufferSequence (
624
+ diskIO: outputIOBox. take ( ) !. consumeIOChannel ( ) ,
625
+ preferredBufferSize: preferredBufferSize
626
+ )
583
627
let result = try await body ( execution, outputSequence)
584
628
try await group. waitForAll ( )
585
629
return result
@@ -593,6 +637,11 @@ public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
593
637
/// - configuration: The configuration to run.
594
638
/// - input: The input to send to the executable.
595
639
/// - output: How to manager executable standard output.
640
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
641
+ /// from the subprocess's standard error stream. If `nil`, uses the system page size
642
+ /// as the default buffer size. Larger buffer sizes may improve performance for
643
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
644
+ /// may reduce memory usage and improve responsiveness for interactive applications.
596
645
/// - isolation: the isolation context to run the body closure.
597
646
/// - body: The custom execution body to manually control the running process
598
647
/// - Returns an executableResult type containing the return value
@@ -601,6 +650,7 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
601
650
_ configuration: Configuration ,
602
651
input: Input = . none,
603
652
output: Output ,
653
+ preferredBufferSize: Int ? = nil ,
604
654
isolation: isolated ( any Actor ) ? = #isolation,
605
655
body: ( ( Execution , AsyncBufferSequence ) async throws -> Result )
606
656
) async throws -> ExecutionResult < Result > where Output. OutputType == Void {
@@ -626,7 +676,10 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
626
676
}
627
677
628
678
// Body runs in the same isolation
629
- let errorSequence = AsyncBufferSequence ( diskIO: errorIOBox. take ( ) !. consumeIOChannel ( ) )
679
+ let errorSequence = AsyncBufferSequence (
680
+ diskIO: errorIOBox. take ( ) !. consumeIOChannel ( ) ,
681
+ preferredBufferSize: preferredBufferSize
682
+ )
630
683
let result = try await body ( execution, errorSequence)
631
684
try await group. waitForAll ( )
632
685
return result
@@ -640,13 +693,19 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
640
693
/// - Parameters:
641
694
/// - configuration: The `Configuration` to run.
642
695
/// - error: How to manager executable standard error.
696
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
697
+ /// from the subprocess's standard output stream. If `nil`, uses the system page size
698
+ /// as the default buffer size. Larger buffer sizes may improve performance for
699
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
700
+ /// may reduce memory usage and improve responsiveness for interactive applications.
643
701
/// - isolation: the isolation context to run the body closure.
644
702
/// - body: The custom execution body to manually control the running process
645
703
/// - Returns an executableResult type containing the return value
646
704
/// of the closure.
647
705
public func run< Result, Error: OutputProtocol > (
648
706
_ configuration: Configuration ,
649
707
error: Error = . discarded,
708
+ preferredBufferSize: Int ? = nil ,
650
709
isolation: isolated ( any Actor ) ? = #isolation,
651
710
body: ( ( Execution , StandardInputWriter , AsyncBufferSequence ) async throws -> Result )
652
711
) async throws -> ExecutionResult < Result > where Error. OutputType == Void {
@@ -658,7 +717,10 @@ public func run<Result, Error: OutputProtocol>(
658
717
error: try error. createPipe ( )
659
718
) { execution, inputIO, outputIO, errorIO in
660
719
let writer = StandardInputWriter ( diskIO: inputIO!)
661
- let outputSequence = AsyncBufferSequence ( diskIO: outputIO!. consumeIOChannel ( ) )
720
+ let outputSequence = AsyncBufferSequence (
721
+ diskIO: outputIO!. consumeIOChannel ( ) ,
722
+ preferredBufferSize: preferredBufferSize
723
+ )
662
724
return try await body ( execution, writer, outputSequence)
663
725
}
664
726
}
@@ -669,13 +731,19 @@ public func run<Result, Error: OutputProtocol>(
669
731
/// - Parameters:
670
732
/// - configuration: The `Configuration` to run.
671
733
/// - output: How to manager executable standard output.
734
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
735
+ /// from the subprocess's standard error stream. If `nil`, uses the system page size
736
+ /// as the default buffer size. Larger buffer sizes may improve performance for
737
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
738
+ /// may reduce memory usage and improve responsiveness for interactive applications.
672
739
/// - isolation: the isolation context to run the body closure.
673
740
/// - body: The custom execution body to manually control the running process
674
741
/// - Returns an executableResult type containing the return value
675
742
/// of the closure.
676
743
public func run< Result, Output: OutputProtocol > (
677
744
_ configuration: Configuration ,
678
745
output: Output ,
746
+ preferredBufferSize: Int ? = nil ,
679
747
isolation: isolated ( any Actor ) ? = #isolation,
680
748
body: ( ( Execution , StandardInputWriter , AsyncBufferSequence ) async throws -> Result )
681
749
) async throws -> ExecutionResult < Result > where Output. OutputType == Void {
@@ -687,21 +755,32 @@ public func run<Result, Output: OutputProtocol>(
687
755
error: try error. createPipe ( )
688
756
) { execution, inputIO, outputIO, errorIO in
689
757
let writer = StandardInputWriter ( diskIO: inputIO!)
690
- let errorSequence = AsyncBufferSequence ( diskIO: errorIO!. consumeIOChannel ( ) )
758
+ let errorSequence = AsyncBufferSequence (
759
+ diskIO: errorIO!. consumeIOChannel ( ) ,
760
+ preferredBufferSize: preferredBufferSize
761
+ )
691
762
return try await body ( execution, writer, errorSequence)
692
763
}
693
764
}
694
765
695
766
/// Run an executable with given parameters specified by a `Configuration`
767
+ /// and a custom closure to manage the running subprocess' lifetime, write to its
768
+ /// standard input, and stream its standard output and standard error.
696
769
/// - Parameters:
697
770
/// - configuration: The `Subprocess` configuration to run.
771
+ /// - preferredBufferSize: The preferred size in bytes for the buffer used when reading
772
+ /// from the subprocess's standard output and error stream. If `nil`, uses the system page size
773
+ /// as the default buffer size. Larger buffer sizes may improve performance for
774
+ /// subprocesses that produce large amounts of output, while smaller buffer sizes
775
+ /// may reduce memory usage and improve responsiveness for interactive applications.
698
776
/// - isolation: the isolation context to run the body closure.
699
777
/// - body: The custom configuration body to manually control
700
778
/// the running process, write to its standard input, stream
701
779
/// the standard output and standard error.
702
780
/// - Returns: an `ExecutableResult` type containing the return value of the closure.
703
781
public func run< Result> (
704
782
_ configuration: Configuration ,
783
+ preferredBufferSize: Int ? = nil ,
705
784
isolation: isolated ( any Actor ) ? = #isolation,
706
785
body: ( ( Execution , StandardInputWriter , AsyncBufferSequence , AsyncBufferSequence ) async throws -> Result )
707
786
) async throws -> ExecutionResult < Result > {
@@ -714,8 +793,14 @@ public func run<Result>(
714
793
error: try error. createPipe ( )
715
794
) { execution, inputIO, outputIO, errorIO in
716
795
let writer = StandardInputWriter ( diskIO: inputIO!)
717
- let outputSequence = AsyncBufferSequence ( diskIO: outputIO!. consumeIOChannel ( ) )
718
- let errorSequence = AsyncBufferSequence ( diskIO: errorIO!. consumeIOChannel ( ) )
796
+ let outputSequence = AsyncBufferSequence (
797
+ diskIO: outputIO!. consumeIOChannel ( ) ,
798
+ preferredBufferSize: preferredBufferSize
799
+ )
800
+ let errorSequence = AsyncBufferSequence (
801
+ diskIO: errorIO!. consumeIOChannel ( ) ,
802
+ preferredBufferSize: preferredBufferSize
803
+ )
719
804
return try await body ( execution, writer, outputSequence, errorSequence)
720
805
}
721
806
}
0 commit comments