const classafConcurrent::SynchronizedBuf

sys::Obj
  afConcurrent::SynchronizedBuf

Provides synchronized multi-thread access to a mutable Buf.

SynchronizedBuf creates a Buf in its own thread and provides access to it via the read and write methods, and complementary InStream and OutStream implementations.

SynchronizedBuf is different to the default Buf.toImmutable() instance because SynchronizedBuf is mutable, designed to be constantly written to by one thread / stream, and constantly read by anther.

.--->--->---                  --->--->---
| Producer  |      Sync      | Consumer  |
▲  Thread   ▼ ---> Buf  <--> ▲  Thread   ▼
|   Loop    |               |   Loop    |
 ---<---<---                  ---<---<---

See Threaded Streams on the Fantom forum for the initial design.

avail

Source

Int avail()

Return the number of bytes available on the input stream without blocking. Return zero if no bytes available or unknown.

in

Source

InStream in()

Creates a thread safe InStream wrapper for this Buf.

make

Source

new make(ActorPool actorPool)

out

Source

OutStream out()

Creates a thread safe OutStream wrapper for this Buf.

read

Source

Int? read()

Read the next unsigned byte from the input stream. Return null if at end of stream.

readBuf

Source

Buf readBuf(Int n)

Attempt to read the next n bytes. Note this method may not read the full number of n bytes.

Source

Int skip(Int n)

Attempt to skip n number of bytes. Return the number of bytes actually skipped which may be equal to or lesser than n.

unread

Source

Void unread(Int b)

Pushback a byte so that it is the next byte to be read. There is a finite limit to the number of bytes which may be pushed back.

write

Source

This write(Int b)

Write a byte to the output stream.

This method return immediately, with the processing happening in the Buf thread.

writeBuf

Source

This writeBuf(Buf buf, Int n := buf.remaining())

Write n bytes from the given Buf at it's current position to the output stream. If n is defaulted to buf.remaining(), then the entire buffer is drained to the output stream.

This method return immediately, with the processing happening in the Buf thread.

Due to the use of Buf.toImmutable() the given Buf is cleared / invalidated upon return.