33using System . Threading . Tasks ;
44using System . Collections . Concurrent ;
55using System . Collections . Generic ;
6- using System . Management . Automation ;
76
87namespace PSParallelPipeline ;
98
109internal sealed class Worker
1110{
1211 private Task ? _worker ;
1312
14- private readonly BlockingCollection < PSTask > _input = [ ] ;
13+ private readonly TaskSettings _taskSettings ;
14+
15+ private readonly BlockingCollection < object ? > _input = [ ] ;
1516
1617 private readonly BlockingCollection < PSOutputData > _output = [ ] ;
1718
1819 private readonly RunspacePool _pool ;
1920
2021 private readonly CancellationToken _token ;
2122
22- private readonly Dictionary < string , object ? > _usingParams ;
23-
2423 private readonly PSOutputStreams _streams ;
2524
2625 internal Worker (
2726 PoolSettings poolSettings ,
28- WorkerSettings workerSettings )
27+ TaskSettings taskSettings ,
28+ CancellationToken token )
2929 {
30- ( _usingParams , _token ) = workerSettings ;
30+ _token = token ;
31+ _taskSettings = taskSettings ;
3132 _streams = new PSOutputStreams ( _output ) ;
3233 _pool = new RunspacePool ( poolSettings , _streams , _token ) ;
3334 }
3435
3536 internal void Wait ( ) => _worker ? . GetAwaiter ( ) . GetResult ( ) ;
3637
37- internal void Enqueue ( object ? input , ScriptBlock script )
38- {
39- _input . Add (
40- item : PSTask
41- . Create ( _pool )
42- . AddInput ( input )
43- . AddScript ( script )
44- . AddUsingStatements ( _usingParams ) ,
45- cancellationToken : _token ) ;
46- }
38+ internal void Enqueue ( object ? input ) => _input . Add ( input , _token ) ;
4739
4840 internal bool TryTake ( out PSOutputData output ) =>
4941 _output . TryTake ( out output , 0 , _token ) ;
@@ -68,9 +60,14 @@ private async Task Start()
6860 await ProcessAnyAsync ( tasks ) ;
6961 }
7062
71- if ( _input . TryTake ( out PSTask ps , 0 , _token ) )
63+ if ( _input . TryTake ( out object ? input , 0 , _token ) )
7264 {
73- tasks . Add ( ps . InvokeAsync ( ) ) ;
65+ PSTask task = await PSTask . CreateAsync (
66+ input : input ,
67+ runspacePool : _pool ,
68+ settings : _taskSettings ) ;
69+
70+ tasks . Add ( task . InvokeAsync ( ) ) ;
7471 }
7572 }
7673
0 commit comments