Skip to content

Commit

Permalink
Added a fix for async try ... with ... expression continuation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachBray committed Oct 27, 2014
1 parent 7d50e5c commit 116dca2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/FunScript/Core/Async.fs
Expand Up @@ -85,7 +85,7 @@ type AsyncBuilder() =
Aux =
{
k.Aux with
ExceptionCont = catchFunction
ExceptionCont = fun ex -> k.Cont(catchFunction ex)
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/tests/FunScript.Tests/AsyncTests.fs
Expand Up @@ -96,3 +96,31 @@ let ``async use statements should dispose of resources when the go out of scope`
step2ok := !isDisposed
!step1ok && !step2ok
@@>


[<Test>]
let ``Try ... with ... expressions inside async expressions work the same``() =
checkAsync
<@
let result = ref ""
let throw() : unit =
raise(exn "Boo!")
let append(x) =
result := !result + x
let innerAsync() =
async {
append "b"
try append "c"
throw()
append "1"
with _ -> append "d"
append "e"
}
async {
append "a"
try do! innerAsync()
with _ -> append "2"
append "f"
return !result
}
@>
14 changes: 14 additions & 0 deletions src/tests/FunScript.Tests/CommonFixture.fs
Expand Up @@ -32,6 +32,20 @@ let check (quote:Quotations.Expr) =
let expectedResult = quote.EvalUntyped()
checkAreEqual expectedResult quote


let checkAsync (quote:Quotations.Expr<'a Async>) =
let expectedResult = <@ Async.RunSynchronously %quote @>.Eval()
let immediateQuote =
<@
let result = ref None
async {
let! v = %quote
result := Some v
} |> Async.StartImmediate
!result |> Option.get
@>
checkAreEqual expectedResult immediateQuote

// TODO:
// Add support for inheritance.
// Add support for TypeScript inheritance.
Expand Down

0 comments on commit 116dca2

Please sign in to comment.