Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit241dbc6

Browse files
v2mKevinRansom
authored andcommitted
subscribe to newline events before starting the process to avoid loosing the data
1 parentd29a5e2 commit241dbc6

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

‎vsintegration/src/vs/FsPkgs/FSharp.VS.FSI/sessions.fs‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ let determineFsiPath () =
171171
else
172172
raise(SessionError(VFSIstrings.SR.couldNotFindFsiExe fsiRegistryPath))
173173

174-
letreadLinesAsync(reader:System.IO.StreamReader):IEvent<string>=
175-
letnewLine= Event<_>()
174+
letreadLinesAsync(reader:System.IO.StreamReader)trigger=
176175
letbuffer= System.Text.StringBuilder(1024)
177176
letbyteBuffer= Array.zeroCreate128
178177
letencoding= System.Text.Encoding.UTF8
@@ -188,7 +187,7 @@ let readLinesAsync(reader: System.IO.StreamReader): IEvent<string> =
188187
letc= buffer.[pos]
189188
if c='\r'|| c='\n'then
190189
letline= buffer.ToString(0, pos)
191-
newLine.Trigger line
190+
trigger line
192191

193192
letdeletePos=
194193
if c='\r'&&(pos+1)< buffer.Length&& buffer.[pos+1]='\n'then pos+2else pos+1
@@ -211,7 +210,6 @@ let readLinesAsync(reader: System.IO.StreamReader): IEvent<string> =
211210
return! read newPos
212211
}
213212
Async.StartImmediate(read0)
214-
newLine.Publish
215213

216214
letfsiStartInfo channelName=
217215
letprocInfo=new ProcessStartInfo()
@@ -251,12 +249,20 @@ let fsiProcess (procInfo:ProcessStartInfo) =
251249
leterrW,errE=lete=new Event<_>()in e.Trigger, e.Publish
252250
letexitE=(cmdProcess.Exited|> Observable.map(fun x-> x))// this gives the event the F# "standard" event type IEvent<'a> rather than IEvent<_,_>
253251

254-
let_= cmdProcess.Start()
255-
// wire up output (to both stdout and stderr)
256-
readLinesAsync cmdProcess.StandardOutput|> catchAll|> Observable.add(fun data->
252+
letstdOutNewLine= Event<_>()
253+
letstdErrNewLine= Event<_>()
254+
255+
// add subscribers prior to hooking to events to avoid data loss if event is emitted before the subscription
256+
stdOutNewLine.Publish|> catchAll|> Observable.add(fun data->
257257
//System.Windows.Forms.MessageBox.Show (sprintf "OutputDataRecieved '%s'\n" data.Data) |> ignore
258-
outW(data));
259-
readLinesAsync cmdProcess.StandardError|> catchAll|> Observable.add(fun data-> errW(data));
258+
outW(data)
259+
);
260+
stdErrNewLine.Publish|> catchAll|> Observable.add(fun data-> errW(data))
261+
262+
let_= cmdProcess.Start()
263+
// hook up stdout\stderr data events
264+
readLinesAsync cmdProcess.StandardOutput stdOutNewLine.Trigger
265+
readLinesAsync cmdProcess.StandardError stdErrNewLine.Trigger
260266

261267
// wire up input
262268
// Fix 982: Force input to be written in UTF8 regardless of the apparent encoding.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp