mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-13 14:53:49 +00:00
Fixed the warning about unsaved changes appearing only by chance (#1050)
This commit is contained in:
1 parent
468d28aa94
commit
c43b52d483
11 files changed
+213
-20
No files matched your search
@@ -208,19 +208,42 @@ public sealed class MessageBus
|
||||
return messages;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asks the receivers a question and returns the first answer.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Every receiver which never narrowed down its events gets the question as well, but only the ones
|
||||
/// which handle it answer. All others return MessageBusAnswer.NONE and are passed over, cf. the remarks
|
||||
/// on MessageBusAnswer for why a bare result cannot express that.
|
||||
/// <br/><br/>
|
||||
/// A question stays within the circuit, i.e., the window, of the sender. The app keeps the circuits of
|
||||
/// reloaded windows around for a long time, cf. the retention settings in Program.cs, and their components
|
||||
/// are still registered: the chat of such an old window must not answer for the one the user is looking
|
||||
/// at. Receivers without a circuit, such as hosted services, serve every window, and a sender without a
|
||||
/// circuit asks all receivers.
|
||||
/// </remarks>
|
||||
/// <param name="sendingComponent">That's you, the sender.</param>
|
||||
/// <param name="triggeredEvent">The question to ask.</param>
|
||||
/// <param name="data">What the question needs to be answered, if anything.</param>
|
||||
/// <returns>The first answer, or the default of TResult when no receiver answers. Asking for unsaved
|
||||
/// changes thus yields false when no chat is open.</returns>
|
||||
public async Task<TResult?> SendMessageUseFirstResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data = default)
|
||||
{
|
||||
var senderCircuit = sendingComponent is IMessageBusReceiver sender && this.receiverCircuits.TryGetValue(sender, out var circuitState) ? circuitState : null;
|
||||
foreach (var (receiver, componentFilter) in this.componentFilters)
|
||||
{
|
||||
if (componentFilter.Length > 0 && sendingComponent is not null && !componentFilter.Contains(sendingComponent))
|
||||
continue;
|
||||
|
||||
if (senderCircuit is not null && this.receiverCircuits.TryGetValue(receiver, out var receiverCircuit) && !ReferenceEquals(receiverCircuit, senderCircuit))
|
||||
continue;
|
||||
|
||||
var eventFilter = this.componentEvents[receiver];
|
||||
if (eventFilter.Length == 0 || eventFilter.Contains(triggeredEvent))
|
||||
{
|
||||
var result = await receiver.ProcessMessageWithResult<TPayload, TResult>(sendingComponent, triggeredEvent, data);
|
||||
if (result is not null)
|
||||
return (TResult) result;
|
||||
var answer = await receiver.ProcessMessageWithResult<TPayload, TResult>(sendingComponent, triggeredEvent, data);
|
||||
if (answer.IsAnswered)
|
||||
return answer.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user