Browse Source
Merge branch 'master' into passwordchar_affects_render
pull/1850/head
Jumar Macato
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
50 additions and
1 deletions
-
src/Avalonia.Base/Threading/Dispatcher.cs
-
src/Avalonia.Base/Threading/IDispatcher.cs
-
tests/Avalonia.UnitTests/ImmediateDispatcher.cs
|
|
|
@ -92,6 +92,20 @@ namespace Avalonia.Threading |
|
|
|
return _jobRunner.InvokeAsync(function, priority); |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public Task InvokeAsync(Func<Task> function, DispatcherPriority priority = DispatcherPriority.Normal) |
|
|
|
{ |
|
|
|
Contract.Requires<ArgumentNullException>(function != null); |
|
|
|
return _jobRunner.InvokeAsync(function, priority).Unwrap(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public Task<TResult> InvokeAsync<TResult>(Func<Task<TResult>> function, DispatcherPriority priority = DispatcherPriority.Normal) |
|
|
|
{ |
|
|
|
Contract.Requires<ArgumentNullException>(function != null); |
|
|
|
return _jobRunner.InvokeAsync(function, priority).Unwrap(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public void Post(Action action, DispatcherPriority priority = DispatcherPriority.Normal) |
|
|
|
{ |
|
|
|
|
|
|
|
@ -40,5 +40,23 @@ namespace Avalonia.Threading |
|
|
|
/// <param name="function">The method.</param>
|
|
|
|
/// <param name="priority">The priority with which to invoke the method.</param>
|
|
|
|
Task<TResult> InvokeAsync<TResult>(Func<TResult> function, DispatcherPriority priority = DispatcherPriority.Normal); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Queues the specified work to run on the dispatcher thread and returns a proxy for the
|
|
|
|
/// task returned by <paramref name="function"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="function">The work to execute asynchronously.</param>
|
|
|
|
/// <param name="priority">The priority with which to invoke the method.</param>
|
|
|
|
/// <returns>A task that represents a proxy for the task returned by <paramref name="function"/>.</returns>
|
|
|
|
Task InvokeAsync(Func<Task> function, DispatcherPriority priority = DispatcherPriority.Normal); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Queues the specified work to run on the dispatcher thread and returns a proxy for the
|
|
|
|
/// task returned by <paramref name="function"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="function">The work to execute asynchronously.</param>
|
|
|
|
/// <param name="priority">The priority with which to invoke the method.</param>
|
|
|
|
/// <returns>A task that represents a proxy for the task returned by <paramref name="function"/>.</returns>
|
|
|
|
Task<TResult> InvokeAsync<TResult>(Func<Task<TResult>> function, DispatcherPriority priority = DispatcherPriority.Normal); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -9,28 +9,45 @@ namespace Avalonia.UnitTests |
|
|
|
/// </summary>
|
|
|
|
public class ImmediateDispatcher : IDispatcher |
|
|
|
{ |
|
|
|
/// <inheritdoc/>
|
|
|
|
public bool CheckAccess() |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public void Post(Action action, DispatcherPriority priority = DispatcherPriority.Normal) |
|
|
|
{ |
|
|
|
action(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public Task InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal) |
|
|
|
{ |
|
|
|
action(); |
|
|
|
return Task.FromResult<object>(null); |
|
|
|
return Task.CompletedTask; |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public Task<TResult> InvokeAsync<TResult>(Func<TResult> function, DispatcherPriority priority = DispatcherPriority.Normal) |
|
|
|
{ |
|
|
|
var result = function(); |
|
|
|
return Task.FromResult(result); |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public Task InvokeAsync(Func<Task> function, DispatcherPriority priority = DispatcherPriority.Normal) |
|
|
|
{ |
|
|
|
return function(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public Task<TResult> InvokeAsync<TResult>(Func<Task<TResult>> function, DispatcherPriority priority = DispatcherPriority.Normal) |
|
|
|
{ |
|
|
|
return function(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public void VerifyAccess() |
|
|
|
{ |
|
|
|
} |
|
|
|
|