Skip to content
This repository was archived by the owner on Jan 25, 2026. It is now read-only.

Commit fc2030a

Browse files
committed
fix(file): 补充未实现的 WaitForResult 逻辑
我当初到底是怎么会忘掉写这部分的 xD
1 parent 2b2b308 commit fc2030a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Service/FileService.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,6 @@ void PushProcess(string? path)
235235
Context.Warn($"文件处理出错: {item}", ex);
236236
result = ex;
237237
}
238-
var atomicResult = new AtomicVariable<object>(result, true, true);
239-
_ProcessResults.AddOrUpdate(item, atomicResult, (_, _) => atomicResult);
240238
}
241239
OnProcessFinished(item, result);
242240
});
@@ -246,6 +244,10 @@ void OnProcessFinished(FileItem finishedItem, object? result, bool removeHandled
246244
{
247245
threadPool.QueueCpu(() =>
248246
{
247+
var atomicResult = new AtomicVariable<object>(result, true, true);
248+
_ProcessResults.AddOrUpdate(item, atomicResult, (_, _) => atomicResult);
249+
// 触发等待事件
250+
if (_WaitForResultEvents.TryGetValue(finishedItem, out var waitEvent)) waitEvent.Set();
249251
try
250252
{
251253
var handled = task.OnProcessFinished(finishedItem, result);
@@ -313,16 +315,17 @@ public static bool TryGetResult(FileItem item, out AnyType? result, bool remove
313315

314316
/// <param name="item">which file to wait for the result</param>
315317
/// <param name="timeout">the maximum waiting time</param>
318+
/// <param name="remove">whether remove from the temp dictionary after successfully get the value</param>
316319
/// <returns>
317320
/// a value, or <c>null</c> if the result is really <c>null</c>, or else, something is boom -
318321
/// I don't know what is wrong but in a word there is something wrong :D
319322
/// </returns>
320-
public static AnyType? WaitForResult(FileItem item, TimeSpan? timeout = null)
323+
public static AnyType? WaitForResult(FileItem item, TimeSpan? timeout = null, bool remove = true)
321324
{
322-
var success = TryGetResult(item, out var result);
325+
var success = TryGetResult(item, out var result, remove);
323326
if (success) return result;
324327
var waitEvent = _WaitForResultEvents.GetOrAdd(item, _ => new ManualResetEventSlim(false));
325-
bool waitResult = true;
328+
var waitResult = true;
326329
if (timeout is { } t) waitResult = waitEvent.Wait(t);
327330
else waitEvent.Wait();
328331
if (!waitResult) return null;

0 commit comments

Comments
 (0)