@@ -72,6 +72,13 @@ let evalExpression text =
7272 match fsiSession.EvalExpression( text) with
7373 | Some value -> printfn " %A " value.ReflectionValue
7474 | None -> printfn " Got no result!"
75+
76+ /// Evaluate expression & return the result, strongly typed
77+ let evalExpressionTyped < 'T > ( text ) =
78+ match fsiSession.EvalExpression( text) with
79+ | Some value -> value.ReflectionValue |> unbox< 'T>
80+ | None -> failwith " Got no result!"
81+
7582(**
7683The `EvalInteraction` method has no result. It can be used to evaluate side-effectful operations
7784such as printing, or other interactions that are not valid F# expressions, but can be entered in
@@ -88,6 +95,7 @@ passed to them does not require `;;` at the end. Just enter the code that you wa
8895evalExpression " 42+1"
8996evalInteraction " printfn \" bye\" "
9097
98+
9199(**
92100The `EvalScript` method allows to evaluate a complete .fsx script.
93101*)
@@ -141,6 +149,28 @@ Gives:
141149*)
142150
143151
152+
153+ (**
154+ Executing in parallel
155+ ------------------
156+
157+ To execute in parallel, submit async computations:
158+ *)
159+
160+ open System.Threading .Tasks
161+
162+ let sampleAsyncExpr =
163+ """
164+ async { do System.Threading.Thread.Sleep 5000
165+ return 10 }
166+ |> Async.StartAsTask"""
167+
168+ let task1 = evalExpressionTyped< Task< int>>( sampleAsyncExpr)
169+ let task2 = evalExpressionTyped< Task< int>>( sampleAsyncExpr)
170+
171+ task1.Result
172+ task2.Result
173+
144174(**
145175Type checking in the evaluation context
146176------------------
0 commit comments