rust - Implementing pipes without using threads -


i working on small language fun , try out ideas. 1 of ideas trying implement piping in shell arbitrary objects. example might make clearer.

the functions range , show_pipe can defined this:

range(n) => {     x := 0;     while x < n {         push x;         x := x + 1;     } } show_pipe() => {     while true {         x := pull;         if x = finishedpipe {             return 0         } else {             print(x)         };     } } 

push pushes value next part of pipeline , suspends function until value needed , pull pulls value pipe , returns or finishedpipe if previous part of pipeline has finished executing.

you can pipe these 2 function range(10) | show_pipe() show numbers 0 through 9 on console.

i'm implementing using thread each part of pipeline , using thread safe queues passing values 1 part of pipe other. find way implement pipes without using threads. using rust can't use coroutines.


Comments