@@ -17,11 +17,9 @@ open AssemblyLoadBuilder
1717open AngouriMath.FSharp .Core
1818open AngouriMath.InteractiveExtension
1919
20-
2120let options = JsonSerializerOptions ()
2221JsonFSharpConverter () |> options.Converters.Add
2322
24-
2523let 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-
4542let 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-
7263let 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