Browse Source

Added comments regarding name scope task completions

pull/2705/head
Nikita Tsukanov 7 years ago
parent
commit
ce28364545
  1. 1
      src/Avalonia.Styling/Controls/INameScope.cs
  2. 3
      src/Avalonia.Styling/Controls/NameScopeLocator.cs
  3. 7
      tests/Avalonia.Controls.UnitTests/NameScopeTests.cs

1
src/Avalonia.Styling/Controls/INameScope.cs

@ -20,6 +20,7 @@ namespace Avalonia.Controls
/// <summary>
/// Finds a named element in the name scope, waits for the scope to be completely populated before returning null
/// Returned task is configured to run any continuations synchronously.
/// </summary>
/// <param name="name">The name.</param>
/// <returns>The element, or null if the name was not found.</returns>

3
src/Avalonia.Styling/Controls/NameScopeLocator.cs

@ -49,6 +49,9 @@ namespace Avalonia.Controls
}
if (_task != null)
// We expect everything to handle callbacks synchronously,
// so the object graph is ready after its built
// so keep TaskContinuationOptions.ExecuteSynchronously
_task.ContinueWith(t =>
{
observer.OnNext(t.Result);

7
tests/Avalonia.Controls.UnitTests/NameScopeTests.cs

@ -51,6 +51,13 @@ namespace Avalonia.Controls.UnitTests
Assert.Throws<InvalidOperationException>(() => target.Register("bar", element));
}
/*
`async void` here is intentional since we expect the continuation to be
executed *synchronously* and behave more like an event handler to make sure that
that the object graph is completely ready to use after it's built
rather than have pending continuations queued by SynchronizationContext.
*/
object _found = null;
async void FindAsync(INameScope scope, string name)
{

Loading…
Cancel
Save