Skip to content

Commit 2efa227

Browse files
authored
Update Terminal Lib
1 parent 51445aa commit 2efa227

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

Sources/Terminal/AngouriMath.Terminal.Lib/FSharpInteractive.fs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ open AssemblyLoadBuilder
1717
open AngouriMath.FSharp.Core
1818
open AngouriMath.InteractiveExtension
1919

20-
2120
let options = JsonSerializerOptions ()
2221
JsonFSharpConverter () |> options.Converters.Add
2322

24-
2523
let private objectEncode (o : obj) =
2624
match o with
2725
| :? ILatexiseable as latexiseable ->
@@ -41,34 +39,27 @@ let private objectDecode (s : string Option) =
4139
JsonSerializer.Deserialize<ExecutionResult> (latex.[EncodingLatexPrefix.Length..], options)
4240
| _ -> VoidSuccess
4341

44-
4542
let execute (kernel : FSharpKernel) code =
4643
let submitCode = SubmitCode code
4744
let computed = (kernel.SendAsync submitCode).Result // Yes. It's Result.
4845

4946
let mutable nonVoidResponse : string Option = None
5047
let mutable res : ExecutionResult Option = None
5148

52-
computed.KernelEvents.Subscribe (new Action<KernelEvent>(fun e ->
53-
match e with
54-
| :? CommandSucceeded ->
55-
res <- objectDecode nonVoidResponse |> Some
56-
| :? CommandFailed as failed ->
57-
res <- Error failed.Message |> Some
58-
| :? DisplayEvent as display ->
59-
nonVoidResponse <- (Seq.head display.FormattedValues).Value |> Some
60-
| _ -> ()
61-
))
62-
|> (fun observer -> observer.Dispose())
49+
for e in computed.Events do
50+
match e with
51+
| :? CommandSucceeded ->
52+
res <- objectDecode nonVoidResponse |> Some
53+
| :? CommandFailed as failed ->
54+
res <- Error failed.Message |> Some
55+
| :? DisplayEvent as display ->
56+
nonVoidResponse <- (Seq.head display.FormattedValues).Value |> Some
57+
| _ -> ()
6358

6459
match res with
6560
| None -> EndOfFile
6661
| Some res -> res
6762

68-
69-
70-
71-
7263
let createKernel () =
7364
let kernel = new FSharpKernel ()
7465

@@ -94,4 +85,4 @@ let createKernel () =
9485
|> (fun f -> Func<GenericChart.GenericChart, string> f)
9586
|> (fun f ->
9687
Formatter.Register<GenericChart.GenericChart> (f, "text/plain"))
97-
}
88+
}

0 commit comments

Comments
 (0)