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

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

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

Definition at line 1606 of file Parallel.cs.

1607 {
1608 if (cancellationToken.IsCancellationRequested)
1609 {
1610 return Task.FromCanceled(cancellationToken);
1611 }
1612 if (dop < 0)
1613 {
1615 }
1617 {
1619 bool launchedNext = false;
1620 try
1621 {
1622 _ = 2;
1623 try
1624 {
1625 while (!state.Cancellation.IsCancellationRequested)
1626 {
1627 await state.Lock.WaitAsync(state.Cancellation.Token);
1628 TSource current;
1629 try
1630 {
1631 if (await state.Enumerator.MoveNextAsync())
1632 {
1633 current = state.Enumerator.Current;
1634 goto IL_016d;
1635 }
1636 }
1637 finally
1638 {
1639 state.Lock.Release();
1640 }
1641 break;
1642 IL_016d:
1643 if (!launchedNext)
1644 {
1645 launchedNext = true;
1646 state.QueueWorkerIfDopAvailable();
1647 }
1648 await state.LoopBody(current, state.Cancellation.Token);
1649 }
1650 }
1651 catch (Exception e)
1652 {
1653 state.RecordException(e);
1654 }
1655 }
1656 finally
1657 {
1658 if (state.SignalWorkerCompletedIterating())
1659 {
1660 try
1661 {
1662 await state.DisposeAsync();
1663 }
1664 catch (Exception e2)
1665 {
1666 state.RecordException(e2);
1667 }
1668 state.Complete();
1669 }
1670 }
1671 };
1672 try
1673 {
1675 asyncForEachAsyncState.QueueWorkerIfDopAvailable();
1676 return asyncForEachAsyncState.Task;
1677 }
1678 catch (Exception exception)
1679 {
1680 return Task.FromException(exception);
1681 }
1682 }

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.