|
19 | 19 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
20 | 20 |
|
21 | 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22 |
| - |
| 22 | + |
23 | 23 | namespace Microsoft.VisualStudio.FSharp.Editor
|
24 | 24 |
|
25 | 25 | // Don't warn about the resumable code invocation
|
@@ -467,8 +467,8 @@ module CancellableTasks =
|
467 | 467 | // Low priority extensions
|
468 | 468 | type CancellableTaskBuilderBase with
|
469 | 469 |
|
470 |
| - [<NoEagerConstraintApplication>] |
471 |
| - member inline _.Source(awaiter: CancellableTask<unit array>) = |
| 470 | + [<NoEagerConstraintApplication>] |
| 471 | + member inline _.Source(awaiter: CancellableTask<unit array>) = |
472 | 472 | (fun (token) -> (awaiter token :> Task).GetAwaiter())
|
473 | 473 |
|
474 | 474 | /// <summary>
|
@@ -611,10 +611,10 @@ module CancellableTasks =
|
611 | 611 | fun sm ->
|
612 | 612 | if __useResumableCode then
|
613 | 613 | sm.Data.ThrowIfCancellationRequested()
|
614 |
| - |
| 614 | + |
615 | 615 | let mutable awaiter = getAwaiter
|
616 | 616 | let mutable __stack_fin = true
|
617 |
| - |
| 617 | + |
618 | 618 | if not (Awaiter.isCompleted awaiter) then
|
619 | 619 | let __stack_yield_fin = ResumableCode.Yield().Invoke(&sm)
|
620 | 620 | __stack_fin <- __stack_yield_fin
|
@@ -706,7 +706,7 @@ module CancellableTasks =
|
706 | 706 | (task: 'Awaitable)
|
707 | 707 | : 'Awaiter =
|
708 | 708 | Awaitable.getAwaiter task
|
709 |
| - |
| 709 | + |
710 | 710 |
|
711 | 711 | /// <summary>Allows the computation expression to turn other types into CancellationToken -> 'Awaiter</summary>
|
712 | 712 | ///
|
@@ -1119,6 +1119,17 @@ module CancellableTasks =
|
1119 | 1119 |
|
1120 | 1120 | let inline ignore ([<InlineIfLambda>] ctask: CancellableTask<_>) = toUnit ctask
|
1121 | 1121 |
|
| 1122 | + /// If this CancellableTask gets canceled for another reason than the token being canceled, return the specified value. |
| 1123 | + let inline ifCanceledReturn value (ctask : CancellableTask<_>) = |
| 1124 | + cancellableTask { |
| 1125 | + let! ct = getCancellationToken () |
| 1126 | + |
| 1127 | + try |
| 1128 | + return! ctask |
| 1129 | + with :? OperationCanceledException when ct.IsCancellationRequested = false -> |
| 1130 | + return value |
| 1131 | + } |
| 1132 | + |
1122 | 1133 | /// <exclude />
|
1123 | 1134 | [<AutoOpen>]
|
1124 | 1135 | module MergeSourcesExtensions =
|
|
0 commit comments