up: PIPE     index Zimbu documentation

CLASS T.pipe<Titem> @public

summary

     

The builtin type pipe.

Pipes are a thread-safe way to send objects from one thread to another thread. Or from one collection of threads to another collection of threads.

Example:

 pipe<string> tp = T.evalThread<string>.NEW().eval({ => "hello thread!" })
 IO.print("from thread: " .. tp.read())

bool  $isOpen @file  state of the pipe
int  $bufferSize @file  maximum number of items buffered
 
NEW() @public  Create a new pipe with buffer size one.
NEW(bufferSize) @public  Create a new pipe with buffer size bufferSize.
$setBufferSize(bufferSize) @public  Change the buffer size to bufferSize.
$close() @public  Close the pipe.
$wait() @public  Wait for the pipe to be empty and closed.
$Size() int @public  Return the number of items currently buffered and ready to be read.
$write(item) status @public  Write one item into the pipe.
$read(st) Titem @public  Read one item from the pipe.
$read() Titem @public  Read one item from the pipe.
 

members (alphabetically)

     

int $bufferSize @file

     

maximum number of items buffered

bool $isOpen @file

     

state of the pipe

PROC NEW() @public

     

Create a new pipe with buffer size one.

PROC NEW(int bufferSize) @public

     

Create a new pipe with buffer size bufferSize.

FUNC $Size() int @public

     

Return the number of items currently buffered and ready to be read.

PROC $close() @public

     

Close the pipe.

All further writes will fail. Reading is still possible so long as there are items to read. Once the pipe is empty reading will fail.

FUNC $read(status &st) Titem @public

     

Read one item from the pipe.

Blocks until an item is available or the pipe is closed. When an item is available st is set to OK. When the pipe is closed st is set to FAIL and return NIL.

FUNC $read() Titem @public

     

Read one item from the pipe.

Blocks until an item is available or the pipe is closed. When an item is available it is returned. When the pipe is closed returns NIL.

PROC $setBufferSize(int bufferSize) @public

     

Change the buffer size to bufferSize.

When the buffer size increases it triggers writers to fill the space. When the buffer size decreases nothing happens, readers must first read any items to get below the new buffer size.

PROC $wait() @public

     

Wait for the pipe to be empty and closed.

FUNC $write(Titem item) status @public

     

Write one item into the pipe.

Blocks until there is space in the pipe buffer. Returns FAIL if the pipe has been closed.

license

      Copyright 2009 Bram Moolenaar All Rights Reserved.

      Licensed under the Apache License, Version 2.0. See the LICENSE file or obtain a copy at: http://www.apache.org/licenses/LICENSE-2.0