|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using System; |
| 6 | + |
| 7 | +namespace CommunityToolkit.Mvvm.Input; |
| 8 | + |
| 9 | +/// <summary> |
| 10 | +/// Options to customize the behavior of <see cref="AsyncRelayCommand"/> and <see cref="AsyncRelayCommand{T}"/> instances. |
| 11 | +/// </summary> |
| 12 | +[Flags] |
| 13 | +public enum AsyncRelayCommandOptions |
| 14 | +{ |
| 15 | + /// <summary> |
| 16 | + /// No option is specified. The <see cref="AsyncRelayCommand"/> and <see cref="AsyncRelayCommand{T}"/> types will use their default behavior: |
| 17 | + /// <list type="bullet"> |
| 18 | + /// <item>Concurrent execution is disallowed: a command is disabled if there is a pending asynchronous execution running.</item> |
| 19 | + /// <item> |
| 20 | + /// <para> |
| 21 | + /// Exceptions are thrown on the calling context: calling <see cref="AsyncRelayCommand.Execute(object?)"/> will await the |
| 22 | + /// returned <see cref="System.Threading.Tasks.Task"/> for the operation, and propagate the exception on the calling context. |
| 23 | + /// </para> |
| 24 | + /// <para>This behavior is consistent with synchronous commands, where exceptions in <see cref="RelayCommand.Execute(object?)"/> behave the same.</para> |
| 25 | + /// </item> |
| 26 | + /// </list> |
| 27 | + /// </summary> |
| 28 | + None = 0, |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// <para>Concurrent executions are allowed. This option makes it so that the same command can be invoked concurrently multiple times.</para> |
| 32 | + /// <para> |
| 33 | + /// Note that additional considerations should be taken into account in this case: |
| 34 | + /// <list type="bullet"> |
| 35 | + /// <item>If the command supports cancellation, previous invocations will automatically be canceled if a new one is started.</item> |
| 36 | + /// <item>The <see cref="AsyncRelayCommand.ExecutionTask"/> property will always represent the operation that was started last.</item> |
| 37 | + /// </list> |
| 38 | + /// </para> |
| 39 | + /// </summary> |
| 40 | + AllowConcurrentExecutions = 1 << 0, |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// <para>Exceptions are not thrown on the calling context, and are propagated to <see cref="System.Threading.Tasks.TaskScheduler.UnobservedTaskException"/> instead.</para> |
| 44 | + /// <para> |
| 45 | + /// This affects how calls to <see cref="AsyncRelayCommand.Execute(object?)"/> behave. When this option is used, if an operation fails, that exception will not |
| 46 | + /// be rethrown on the calling context (as it is not awaited there). Instead, it will flow to <see cref="System.Threading.Tasks.TaskScheduler.UnobservedTaskException"/>. |
| 47 | + /// </para> |
| 48 | + /// <para> |
| 49 | + /// This option enables more advanced scenarios, where the <see cref="AsyncRelayCommand.ExecutionTask"/> property can be used to inspect the state of an operation |
| 50 | + /// that was queued. That is, even if the operation failed or was canceled, the details of that can be retrieved at a later time by accessing this property. |
| 51 | + /// </para> |
| 52 | + /// </summary> |
| 53 | + FlowExceptionsToTaskScheduler = 1 << 1 |
| 54 | +} |
0 commit comments