Fix race condition with Do and async

This commit is contained in:
Timothy Baldridge 2020-05-25 13:41:16 -06:00
parent b2a112bd37
commit 1099d68ef7
2 changed files with 13 additions and 2 deletions

View File

@ -300,6 +300,17 @@ namespace Wabbajack.Common
{
foreach (var i in coll) f(i);
}
/// <summary>
/// Executes the action for every item in coll
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="coll"></param>
/// <param name="f"></param>
public static async Task DoAsync<T>(this IEnumerable<T> coll, Func<T, Task> f)
{
foreach (var i in coll) await f(i);
}
public static void DoIndexed<T>(this IEnumerable<T> coll, Action<int, T> f)
{

View File

@ -148,7 +148,7 @@ namespace Wabbajack.VirtualFileSystem
bw.Write(FileVersion);
bw.Write((ulong) Index.AllFiles.Count);
(await Index.AllFiles
await (await Index.AllFiles
.PMap(Queue, f =>
{
var ms = new MemoryStream();
@ -156,7 +156,7 @@ namespace Wabbajack.VirtualFileSystem
f.Write(ibw);
return ms;
}))
.Do(async ms =>
.DoAsync(async ms =>
{
var size = ms.Position;
ms.Position = 0;