Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
fix 3171 (dotnet#3182)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyme authored and KevinRansom committed Jun 7, 2017
1 parent db75456 commit 753323f
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions Common/RoslynHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ module internal RoslynHelpers =
member __.Proceed = not isStopped
member __.Stop() = isStopped <- true

// This is like Async.StartAsTask, but if cancellation occurs we explicitly associate the cancellation with cancellationToken
// This is like Async.StartAsTask, but
// 1. if cancellation occurs we explicitly associate the cancellation with cancellationToken
// 2. if exception occurs then set result to Unchecked.defaultof<_>, i.e. swallow exceptions
// and hope that Roslyn copes with the null
let StartAsyncAsTask (cancellationToken: CancellationToken) computation =
let tcs = new TaskCompletionSource<_>(TaskCreationOptions.None)
let barrier = VolatileBarrier()
Expand All @@ -102,10 +105,24 @@ module internal RoslynHelpers =
Async.StartWithContinuations(
async { do! Async.SwitchToThreadPool()
return! computation },
continuation=(fun result -> disposeReg(); tcs.TrySetResult(result) |> ignore),
exceptionContinuation=(function :? OperationCanceledException -> disposeReg(); tcs.TrySetCanceled(cancellationToken) |> ignore
| exn -> disposeReg(); tcs.TrySetException(exn) |> ignore),
cancellationContinuation=(fun _oce -> disposeReg(); tcs.TrySetCanceled(cancellationToken) |> ignore),
continuation=(fun result ->
disposeReg()
tcs.TrySetResult(result) |> ignore
),
exceptionContinuation=(fun exn ->
disposeReg()
match exn with
| :? OperationCanceledException ->
tcs.TrySetCanceled(cancellationToken) |> ignore
| exn ->
System.Diagnostics.Trace.WriteLine("Visual F# Tools: exception swallowed and not passed to Roslyn: {0}", exn.Message)
let res = Unchecked.defaultof<_>
tcs.TrySetResult(res) |> ignore
),
cancellationContinuation=(fun _oce ->
disposeReg()
tcs.TrySetCanceled(cancellationToken) |> ignore
),
cancellationToken=cancellationToken)
task

Expand Down

0 comments on commit 753323f

Please sign in to comment.