File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change 11use std:: {
2- io:: Write ,
2+ io:: { Read , Write } ,
33 path:: { Path , PathBuf } ,
44 process:: Stdio ,
55 thread:: sleep,
@@ -77,8 +77,20 @@ fn http_example() -> anyhow::Result<()> {
7777 let mut handle = std:: process:: Command :: new ( "wasmtime" )
7878 . current_dir ( & path)
7979 . args ( [ "serve" , "--wasi" , "common" , "http.wasm" ] )
80+ . stdout ( Stdio :: piped ( ) )
8081 . spawn ( ) ?;
8182
83+ let mut buf = [ 0 ; 64 ] ;
84+ let mut stdout = handle. stdout . take ( ) . unwrap ( ) ;
85+
86+ // Read at least one byte from stdout
87+ retry ( || -> anyhow:: Result < ( ) > {
88+ if buf. is_empty ( ) && stdout. read ( & mut buf) ? == 0 {
89+ return Err ( anyhow:: anyhow!( "No data" ) ) ;
90+ }
91+ Ok ( ( ) )
92+ } ) ?;
93+
8294 let content = "’Twas brillig, and the slithy toves
8395 Did gyre and gimble in the wabe:
8496All mimsy were the borogoves,
@@ -272,8 +284,8 @@ fn tcp_example() -> anyhow::Result<()> {
272284 Ok ( ( ) )
273285}
274286
275- fn retry < T > ( func : impl Fn ( ) -> anyhow:: Result < T > ) -> anyhow:: Result < T > {
276- for i in 0 ..10 {
287+ fn retry < T > ( mut func : impl FnMut ( ) -> anyhow:: Result < T > ) -> anyhow:: Result < T > {
288+ for i in 0 ..5 {
277289 match func ( ) {
278290 Ok ( t) => {
279291 return Ok ( t) ;
You can’t perform that action at this time.
0 commit comments