Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ForEachAsync< TSource >() [7/8]

static Task System.Threading.Tasks.Parallel.ForEachAsync< TSource > ( IEnumerable< TSource > source,
int dop,
TaskScheduler scheduler,
CancellationToken cancellationToken,
Func< TSource, CancellationToken, ValueTask > body )
inlinestaticprivate

Definition at line 1496 of file Parallel.cs.

1497 {
1498 if (cancellationToken.IsCancellationRequested)
1499 {
1500 return Task.FromCanceled(cancellationToken);
1501 }
1502 if (dop < 0)
1503 {
1505 }
1507 {
1509 bool launchedNext = false;
1510 try
1511 {
1512 while (!state.Cancellation.IsCancellationRequested)
1513 {
1514 TSource current;
1515 lock (state)
1516 {
1517 if (!state.Enumerator.MoveNext())
1518 {
1519 break;
1520 }
1521 current = state.Enumerator.Current;
1522 }
1523 if (!launchedNext)
1524 {
1525 launchedNext = true;
1526 state.QueueWorkerIfDopAvailable();
1527 }
1528 await state.LoopBody(current, state.Cancellation.Token);
1529 }
1530 }
1531 catch (Exception e)
1532 {
1533 state.RecordException(e);
1534 }
1535 finally
1536 {
1537 if (state.SignalWorkerCompletedIterating())
1538 {
1539 try
1540 {
1541 state.Dispose();
1542 }
1543 catch (Exception e2)
1544 {
1545 state.RecordException(e2);
1546 }
1547 state.Complete();
1548 }
1549 }
1550 };
1551 try
1552 {
1554 syncForEachAsyncState.QueueWorkerIfDopAvailable();
1555 return syncForEachAsyncState.Task;
1556 }
1557 catch (Exception exception)
1558 {
1559 return Task.FromException(exception);
1560 }
1561 }

References System.cancellationToken, System.Threading.Tasks.Parallel.DefaultDegreeOfParallelism, System.exception, System.Threading.Tasks.Task< TResult >.FromCanceled(), System.Threading.Tasks.Task< TResult >.FromException(), System.scheduler, System.source, and System.state.