Merge pull request #302 from Noggog/pmap-overload

Added another missing PMap overload
This commit is contained in:
Timothy Baldridge 2019-12-22 13:57:23 -08:00 committed by GitHub
commit 04c9055005
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 9 deletions

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Wabbajack.Common
{
public static class ProcessExt
{
public static void WaitForExitAndWarn(this Process process, TimeSpan warningTimeout, string processTitle)
{
if (!process.WaitForExit((int)warningTimeout.TotalMilliseconds))
{
Utils.Status($"{processTitle} - Taking a long time to exit.", alsoLog: true);
process.WaitForExit();
Utils.Status($"{processTitle} - Exited after a long period.", alsoLog: true);
}
}
}
}

View File

@ -107,7 +107,7 @@ namespace Wabbajack.Common
Utils.Error(e, "Error while reading StandardOutput for innounp.exe");
}
p.WaitForExit();
p.WaitForExitAndWarn(TimeSpan.FromSeconds(30), $"Extracting {name}");
if (p.ExitCode == 0)
return;
@ -204,7 +204,8 @@ namespace Wabbajack.Common
{
}
p.WaitForExit();
p.WaitForExitAndWarn(TimeSpan.FromSeconds(30), $"Extracting {name}");
if (p.ExitCode == 0)
{
return;
@ -254,7 +255,7 @@ namespace Wabbajack.Common
Utils.Status($"Testing {name} - {line.Trim()}");
}
p.WaitForExit();
p.WaitForExitAndWarn(TimeSpan.FromSeconds(30), $"Testing {name}");
return p.ExitCode == 0;
}
@ -291,7 +292,7 @@ namespace Wabbajack.Common
}
} catch (Exception){}
testP.WaitForExit();
testP.WaitForExitAndWarn(TimeSpan.FromSeconds(30), $"Can Extract Check {v}");
return testP.ExitCode == 0;
}
}

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Data.HashFunction.xxHash;
using System.Diagnostics;
@ -121,9 +121,13 @@ namespace Wabbajack.Common
}
}
public static void Status(string msg, int progress = 0)
public static void Status(string msg, int progress = 0, bool alsoLog = false)
{
WorkQueue.AsyncLocalCurrentQueue.Value?.Report(msg, progress);
if (alsoLog)
{
Utils.Log(msg);
}
}
/// <summary>
@ -541,6 +545,18 @@ namespace Wabbajack.Common
});
}
public static async Task PMap<TI>(this IEnumerable<TI> coll, WorkQueue queue, StatusUpdateTracker updateTracker,
Func<TI, Task> f)
{
var cnt = 0;
var collist = coll.ToList();
await collist.PMap(queue, async itm =>
{
updateTracker.MakeUpdate(collist.Count, Interlocked.Increment(ref cnt));
await f(itm);
});
}
public static async Task PMap<TI>(this IEnumerable<TI> coll, WorkQueue queue, StatusUpdateTracker updateTracker,
Action<TI> f)
{
@ -554,7 +570,6 @@ namespace Wabbajack.Common
});
}
public static async Task<TR[]> PMap<TI, TR>(this IEnumerable<TI> coll, WorkQueue queue,
Func<TI, TR> f)
{
@ -592,7 +607,6 @@ namespace Wabbajack.Common
return await Task.WhenAll(tasks);
}
public static async Task<TR[]> PMap<TI, TR>(this IEnumerable<TI> coll, WorkQueue queue,
Func<TI, Task<TR>> f)
{
@ -994,7 +1008,7 @@ namespace Wabbajack.Common
if (line == null) break;
Status(line);
}
p.WaitForExit();
p.WaitForExitAndWarn(TimeSpan.FromSeconds(30), $"Deletion process of {path}");
}
/// <summary>

View File

@ -103,6 +103,7 @@
<Compile Include="Extensions\EnumerableExt.cs" />
<Compile Include="Extensions\EnumExt.cs" />
<Compile Include="Extensions\HashHelper.cs" />
<Compile Include="Extensions\ProcessExt.cs" />
<Compile Include="Extensions\RxExt.cs" />
<Compile Include="Extensions\TaskExt.cs" />
<Compile Include="FileExtractor.cs" />