Skip to content

Commit

Permalink
feature(pipes): <connected-pair>
Browse files Browse the repository at this point in the history
Introduce a word to open two pipes that are connected to each other.

Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg authored and mrjbq7 committed May 30, 2024
1 parent 7e40be7 commit 6e8cf4f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions basis/io/pipes/pipes-tests.factor
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,15 @@ io.timeouts kernel math namespaces threads tools.test ;
[ 0 read ] with-input-stream
] with-destructors
] unit-test

{ "bar" "foo" } [
[
[let
utf8 <connected-pair> :> ( x y )
x y [ &dispose drop ] bi@
"foo\n" x stream-write x stream-flush
"bar\n" y stream-write y stream-flush
x y [ stream-readln ] bi@
]
] with-destructors
] unit-test
6 changes: 6 additions & 0 deletions basis/io/pipes/pipes.factor
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ HOOK: (pipe) io-backend ( -- pipe )
] dip <encoder-duplex>
] with-destructors ;

:: <connected-pair> ( encoding -- stream stream )
encoding <pipe> :> x encoding <pipe> :> y
x in>> :> xin y in>> :> yin
yin x in<< xin y in<<
x y ;

<PRIVATE

: ?reader ( handle/f -- stream )
Expand Down

0 comments on commit 6e8cf4f

Please sign in to comment.