Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BatchedJoinBlock.cs
Go to the documentation of this file.
5
7
8[DebuggerDisplay("{DebuggerDisplayContent,nq}")]
10public sealed class BatchedJoinBlock<T1, T2> : IReceivableSourceBlock<Tuple<IList<T1>, IList<T2>>>, ISourceBlock<Tuple<IList<T1>, IList<T2>>>, IDataflowBlock, IDebuggerDisplay
11{
12 private sealed class DebugView
13 {
15
16 private readonly SourceCore<Tuple<IList<T1>, IList<T2>>>.DebuggingInformation _sourceDebuggingInformation;
17
19
21
23
25
27
29
30 public Task TaskForOutputProcessing => _sourceDebuggingInformation.TaskForOutputProcessing;
31
33
34 public bool IsCompleted => _sourceDebuggingInformation.IsCompleted;
35
37
39
41
47 }
48
49 private readonly int _batchSize;
50
52
54
56
58
59 public int BatchSize => _batchSize;
60
62
64
65 public int OutputCount => _source.OutputCount;
66
67 public Task Completion => _source.Completion;
68
69 private int OutputCountForDebugger => _source.GetDebuggingInformation().OutputCount;
70
71 private object DebuggerDisplayContent => $"{Common.GetNameForDebugger(this, _source.DataflowBlockOptions)}, BatchSize={BatchSize}, OutputCount={OutputCountForDebugger}";
72
73 object IDebuggerDisplay.Content => DebuggerDisplayContent;
74
79
81 {
82 if (batchSize < 1)
83 {
85 }
86 if (dataflowBlockOptions == null)
87 {
88 throw new ArgumentNullException("dataflowBlockOptions");
89 }
90 if (!dataflowBlockOptions.Greedy)
91 {
92 throw new ArgumentException(System.SR.Argument_NonGreedyNotSupported, "dataflowBlockOptions");
93 }
94 if (dataflowBlockOptions.BoundedCapacity != -1)
95 {
96 throw new ArgumentException(System.SR.Argument_BoundedCapacityNotSupported, "dataflowBlockOptions");
97 }
101 {
102 ((BatchedJoinBlock<T1, T2>)owningSource).CompleteEachTarget();
103 });
105 {
106 if (_target1.Count > 0 || _target2.Count > 0)
107 {
109 }
110 };
112 {
114 _source.Complete();
115 }, _source.AddException, Complete);
118 _source.Completion.ContinueWith(delegate(Task completed, object state)
119 {
121 dataflowBlock.Fault(completed.Exception);
123 Common.WireCancellationToComplete(dataflowBlockOptions.CancellationToken, _source.Completion, delegate(object state)
124 {
125 ((BatchedJoinBlock<T1, T2>)state).CompleteEachTarget();
126 }, this);
128 if (log.IsEnabled())
129 {
130 log.DataflowBlockCreated(this, dataflowBlockOptions);
131 }
132 }
133
135 {
136 return _source.LinkTo(target, linkOptions);
137 }
138
140 {
141 return _source.TryReceive(filter, out item);
142 }
143
145 {
146 return _source.TryReceiveAll(out items);
147 }
148
149 public void Complete()
150 {
153 }
154
156 {
157 if (exception == null)
158 {
159 throw new ArgumentNullException("exception");
160 }
162 {
164 {
165 _source.AddException(exception);
166 }
167 }
168 Complete();
169 }
170
175
177 {
178 return _source.ReserveMessage(messageHeader, target);
179 }
180
182 {
183 _source.ReleaseReservation(messageHeader, target);
184 }
185
186 private void CompleteEachTarget()
187 {
190 }
191
192 public override string ToString()
193 {
194 return Common.GetNameForDebugger(this, _source.DataflowBlockOptions);
195 }
196}
197[DebuggerDisplay("{DebuggerDisplayContent,nq}")]
199public sealed class BatchedJoinBlock<T1, T2, T3> : IReceivableSourceBlock<Tuple<IList<T1>, IList<T2>, IList<T3>>>, ISourceBlock<Tuple<IList<T1>, IList<T2>, IList<T3>>>, IDataflowBlock, IDebuggerDisplay
200{
201 private sealed class DebugView
202 {
204
206
208
210
212
214
216
218
220
221 public Task TaskForOutputProcessing => _sourceDebuggingInformation.TaskForOutputProcessing;
222
224
225 public bool IsCompleted => _sourceDebuggingInformation.IsCompleted;
226
227 public int Id => Common.GetBlockId(_batchedJoinBlock);
228
230
232
238 }
239
240 private readonly int _batchSize;
241
243
244 private readonly BatchedJoinBlockTarget<T1> _target1;
245
246 private readonly BatchedJoinBlockTarget<T2> _target2;
247
249
251
252 public int BatchSize => _batchSize;
253
255
257
259
260 public int OutputCount => _source.OutputCount;
261
262 public Task Completion => _source.Completion;
263
264 private int OutputCountForDebugger => _source.GetDebuggingInformation().OutputCount;
265
266 private object DebuggerDisplayContent => $"{Common.GetNameForDebugger(this, _source.DataflowBlockOptions)}, BatchSize={BatchSize}, OutputCount={OutputCountForDebugger}";
267
268 object IDebuggerDisplay.Content => DebuggerDisplayContent;
269
274
276 {
277 if (batchSize < 1)
278 {
280 }
281 if (dataflowBlockOptions == null)
282 {
283 throw new ArgumentNullException("dataflowBlockOptions");
284 }
285 if (!dataflowBlockOptions.Greedy || dataflowBlockOptions.BoundedCapacity != -1)
286 {
287 throw new ArgumentException(System.SR.Argument_NonGreedyNotSupported, "dataflowBlockOptions");
288 }
292 {
293 ((BatchedJoinBlock<T1, T2, T3>)owningSource).CompleteEachTarget();
294 });
296 {
297 if (_target1.Count > 0 || _target2.Count > 0 || _target3.Count > 0)
298 {
300 }
301 };
303 {
305 _source.Complete();
306 }, _source.AddException, Complete);
310 _source.Completion.ContinueWith(delegate(Task completed, object state)
311 {
313 dataflowBlock.Fault(completed.Exception);
315 Common.WireCancellationToComplete(dataflowBlockOptions.CancellationToken, _source.Completion, delegate(object state)
316 {
317 ((BatchedJoinBlock<T1, T2, T3>)state).CompleteEachTarget();
318 }, this);
320 if (log.IsEnabled())
321 {
322 log.DataflowBlockCreated(this, dataflowBlockOptions);
323 }
324 }
325
330
332 {
333 return _source.TryReceive(filter, out item);
334 }
335
337 {
338 return _source.TryReceiveAll(out items);
339 }
340
341 public void Complete()
342 {
346 }
347
349 {
350 if (exception == null)
351 {
352 throw new ArgumentNullException("exception");
353 }
355 {
357 {
358 _source.AddException(exception);
359 }
360 }
361 Complete();
362 }
363
368
373
375 {
376 _source.ReleaseReservation(messageHeader, target);
377 }
378
379 private void CompleteEachTarget()
380 {
384 }
385
386 public override string ToString()
387 {
388 return Common.GetNameForDebugger(this, _source.DataflowBlockOptions);
389 }
390}
static string Argument_BoundedCapacityNotSupported
Definition SR.cs:20
static string ArgumentOutOfRange_GenericPositive
Definition SR.cs:1018
static string Argument_NonGreedyNotSupported
Definition SR.cs:28
Definition SR.cs:7
IEnumerable< Tuple< IList< T1 >, IList< T2 > > > OutputQueue
DebugView(BatchedJoinBlock< T1, T2 > batchedJoinBlock)
readonly SourceCore< Tuple< IList< T1 >, IList< T2 > > >.DebuggingInformation _sourceDebuggingInformation
TargetRegistry< Tuple< IList< T1 >, IList< T2 > > > LinkedTargets
ITargetBlock< Tuple< IList< T1 >, IList< T2 > > > NextMessageReservedFor
readonly SourceCore< Tuple< IList< T1 >, IList< T2 >, IList< T3 > > >.DebuggingInformation _sourceDebuggingInformation
readonly BatchedJoinBlock< T1, T2, T3 > _batchedJoinBlock
DebugView(BatchedJoinBlock< T1, T2, T3 > batchedJoinBlock)
IDisposable LinkTo(ITargetBlock< Tuple< IList< T1 >, IList< T2 > > > target, DataflowLinkOptions linkOptions)
readonly SourceCore< Tuple< IList< T1 >, IList< T2 > > > _source
readonly BatchedJoinBlockTargetSharedResources _sharedResources
readonly SourceCore< Tuple< IList< T1 >, IList< T2 >, IList< T3 > > > _source
bool TryReceive(Predicate< Tuple< IList< T1 >, IList< T2 > > >? filter, [NotNullWhen(true)] out Tuple< IList< T1 >, IList< T2 > >? item)
readonly BatchedJoinBlockTarget< T2 > _target2
readonly BatchedJoinBlockTarget< T1 > _target1
BatchedJoinBlock(int batchSize, GroupingDataflowBlockOptions dataflowBlockOptions)
bool TryReceiveAll([NotNullWhen(true)] out IList< Tuple< IList< T1 >, IList< T2 > > >? items)
readonly BatchedJoinBlockTarget< T3 > _target3
IDisposable LinkTo(ITargetBlock< Tuple< IList< T1 >, IList< T2 >, IList< T3 > > > target, DataflowLinkOptions linkOptions)
bool TryReceiveAll([NotNullWhen(true)] out IList< Tuple< IList< T1 >, IList< T2 >, IList< T3 > > >? items)
bool TryReceive(Predicate< Tuple< IList< T1 >, IList< T2 >, IList< T3 > > >? filter, [NotNullWhen(true)] out Tuple< IList< T1 >, IList< T2 >, IList< T3 > >? item)
static TaskContinuationOptions GetContinuationOptions(TaskContinuationOptions toInclude=TaskContinuationOptions.None)
Definition Common.cs:262
static string GetNameForDebugger(IDataflowBlock block, DataflowBlockOptions options=null)
Definition Common.cs:66
static void WireCancellationToComplete(CancellationToken cancellationToken, Task completionTask, Action< object > completeAction, object completeState)
Definition Common.cs:93
static int GetBlockId(IDataflowBlock block)
Definition Common.cs:61