Browse Source
* Added guards for compositor reentrancy and exposed batch lifetime events * Use manual continue with since our tests are using some borked sync contextrelease/11.0.5-rc1
committed by
Steven Kirk
9 changed files with 148 additions and 34 deletions
@ -0,0 +1,40 @@ |
|||
using System; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Avalonia.Threading; |
|||
|
|||
public class DispatcherPriorityAwaitable : INotifyCompletion |
|||
{ |
|||
private readonly Dispatcher _dispatcher; |
|||
private protected readonly Task Task; |
|||
private readonly DispatcherPriority _priority; |
|||
|
|||
internal DispatcherPriorityAwaitable(Dispatcher dispatcher, Task task, DispatcherPriority priority) |
|||
{ |
|||
_dispatcher = dispatcher; |
|||
Task = task; |
|||
_priority = priority; |
|||
} |
|||
|
|||
public void OnCompleted(Action continuation) => |
|||
Task.ContinueWith(_ => _dispatcher.Post(continuation, _priority)); |
|||
|
|||
public bool IsCompleted => Task.IsCompleted; |
|||
|
|||
public void GetResult() => Task.GetAwaiter().GetResult(); |
|||
|
|||
public DispatcherPriorityAwaitable GetAwaiter() => this; |
|||
} |
|||
|
|||
public class DispatcherPriorityAwaitable<T> : DispatcherPriorityAwaitable |
|||
{ |
|||
internal DispatcherPriorityAwaitable(Dispatcher dispatcher, Task<T> task, DispatcherPriority priority) : base( |
|||
dispatcher, task, priority) |
|||
{ |
|||
} |
|||
|
|||
public new T GetResult() => ((Task<T>)Task).GetAwaiter().GetResult(); |
|||
|
|||
public new DispatcherPriorityAwaitable<T> GetAwaiter() => this; |
|||
} |
|||
Loading…
Reference in new issue