Skip to content

Commit f509b5a

Browse files
committed
update docs for #482
1 parent b1653fb commit f509b5a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/content/interactive.fsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
(**
7683
The `EvalInteraction` method has no result. It can be used to evaluate side-effectful operations
7784
such 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
8895
evalExpression "42+1"
8996
evalInteraction "printfn \"bye\""
9097

98+
9199
(**
92100
The `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
(**
145175
Type checking in the evaluation context
146176
------------------

0 commit comments

Comments
 (0)