Skip to content

Commit 8e58c9d

Browse files
forkiKevinRansom
authored andcommitted
Remove uncommented code in Async.Parallel and test for proper cancellation
1 parent bc367dc commit 8e58c9d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Control/AsyncModule.fs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,26 @@ type AsyncModule() =
294294
member this.``RaceBetweenCancellationAndError.Sleep``() =
295295
testErrorAndCancelRace (Async.Sleep (-5))
296296

297+
298+
[<Test>]
299+
member this.``error on one workflow should cancel all others``() =
300+
let counter =
301+
async {
302+
let counter = ref 0
303+
let job i = async {
304+
if i = 55 then failwith "boom"
305+
else
306+
do! Async.Sleep 1000
307+
incr counter
308+
}
309+
310+
let! _ = Async.Parallel [ for i in 1 .. 100 -> job i ] |> Async.Catch
311+
do! Async.Sleep 5000
312+
return !counter
313+
} |> Async.RunSynchronously
314+
315+
Assert.AreEqual(0, counter)
316+
297317
[<Test>]
298318
member this.``AwaitWaitHandle.ExceptionsAfterTimeout``() =
299319
let wh = new System.Threading.ManualResetEvent(false)

src/fsharp/FSharp.Core/control.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,8 +1414,7 @@ namespace Microsoft.FSharp.Control
14141414
let count = ref tasks.Length
14151415
let firstExn = ref None
14161416
let results = Array.zeroCreate tasks.Length
1417-
// Attept to cancel the individual operations if an exception happens on any the other threads
1418-
//let failureCTS = new CancellationTokenSource()
1417+
// Attept to cancel the individual operations if an exception happens on any of the other threads
14191418
let innerCTS = new LinkedSubSource(aux.token)
14201419
let trampolineHolder = aux.trampolineHolder
14211420

0 commit comments

Comments
 (0)