A Pipe to the Future
Peter William Lount
peter at smalltalk.org
Thu Sep 6 03:58:44 UTC 2007
Hi,
Thanks for the excellent example.
Considering the idea to have a "wrapper" that generates whatever code is
needed underneath for the piping syntax so that piping works for single
Smalltalk processes as well as multiple processes in one image or across
images may have benefits.
Cheers,
Peter
Michael van der Gulik wrote:
>
>
> On 9/6/07, *Peter William Lount* <peter at smalltalk.org
> <mailto:peter at smalltalk.org>> wrote:
>
> Hi,
>
> I am wondering if the following would be possible and if so how?
>
> aProcess := [ "a block that pumps out continuous values"] fork.
> bProcess := [:in | in someOperation ] fork.
>
> "pipe the results of process a into process b like in unix shell"
> aProcess asPipeInto: bProcess.
>
> or
>
> aProcess | bProcess
>
>
> It's easier to do it directly.
>
> keepGoing := true.
> s := SharedQueue new.
> [ 1 to: 100 do: [ :each | s nextPut: each ] ] fork.
> [ [keepGoing] whileTrue: [Transcript show: s next asString, ' ']. ] fork.
>
> And then:
> keepGoing := false. "To stop the second process."
>
> The SharedQueue acts like the pipe. You could make your own class to
> add a layer of abstraction, but this would only be worthwhile if you
> are having difficulty with the complexity.
>
> Michael.
>
>
>
More information about the Squeak-dev
mailing list
|