NotifyingQueue

Templated Notifying Queue implementation

A concrete client should have an instance of this class and use it to manage the connections and requests

Note: the stored type T is automatically de/serialized using the StructSerializer. This performs a deep serialization of sub-structs and array members. Union members are shallowly serialized. Delegate and class members cannot be serialized.

Constructors

this
this(size_t max_bytes)

Constructor

this
this(IByteQueue queue)

Constructor

Members

Aliases

push
alias push = NotifyingByteQueue.push
Undocumented in source.

Functions

pop
T* pop(void[] buffer)

Pops a Request instance from the queue

pop
T* pop(Contiguous!(T) cont_buffer)

Pops a Request instance from the queue

push
bool push(T request)

Push a new request on the queue

Inherited Members

From NotifyingByteQueue

NotificationDg
alias NotificationDg = void delegate()

Type of the delegate used for notifications

willFit
bool willFit(size_t bytes)

Finds out whether the provided number of bytes will fit in the queue. Also considers the need of wrapping.

total_space
ulong total_space()
used_space
ulong used_space()
free_space
ulong free_space()
length
size_t length()
is_empty
bool is_empty()

Tells whether the queue is empty.

ready
bool ready(NotificationDg notifier)

register an handler as available

isRegistered
bool isRegistered(NotificationDg notifier)

Check whether the provided notifier is already registered. This allows the code to avoid calling ready() with the same notifier, which may throw or add duplicate notifiers.

waiting
size_t waiting()
push
bool push(void[] data)

Push an item into the queue and notify the next waiting notification delegate about it.

push
bool push(size_t size, void delegate(void[]) filler)

Push an item into the queue and notify the next waiting handler about it.

suspend
void suspend()

suspend consuming of the queue

suspended
bool suspended()

Returns true if the queue is suspended, else false

resume
void resume()

resume consuming of the queue

pop
void[] pop()

pops an element if the queue is enabled

Parameters

T

type that the queue should store. If it's a struct it is stored using the struct serializer, else it is storing it directly. Note that by default the memory is not gc-aware so you reference something from only the stored object, the gc could collect it. If you desire different behavior pass your own queue instance to the constructor

Examples

NotifyingQueue with a non-struct type

auto queue = new NotifyingQueue!(char[])(1024);

char[][] arr = ["foo".dup, "bar".dup];

queue.push(arr[0]);
queue.push(arr[1]);

void[] buffer_1;

auto str_0 = queue.pop(buffer_1);

test!("==")(*str_0, "foo");

void[] buffer_2;

auto str_1 = queue.pop(buffer_2);

test!("==")(*str_0, "foo");  // ensure there was no overwrite
test!("==")(*str_1, "bar");

NotifyingQueue with a struct

struct S { char[] value; }

S[2] arr = [S("foo".dup), S("bar".dup)];

auto queue = new NotifyingQueue!(S)(1024);

queue.push(arr[0]);
queue.push(arr[1]);

Contiguous!(S) ctg_1;

auto s0 = queue.pop(ctg_1);

test!("==")(s0.value, "foo");

Contiguous!(S) ctg_2;

auto s1 = queue.pop(ctg_2);

test!("==")(s0.value, "foo");  // ensure there was no overwrite
test!("==")(s1.value, "bar");

Meta