Vely logo install | documentation | examples | changelog
16.10.0 released May 10, 2023
read-fifo

Purpose: Reads key/value pair from a FIFO list.

read-fifo <list> \
    key [ define ] <key> \
    value [ define ] <value>

read-fifo retrieves an element from the FIFO <list>, storing it into <key> pointer (in "key" clause) and <value> pointer (in "value" clause), both of which can be created as strings with optional "define".

Once an element has been retrieved, the next use of read-fifo will obtain the following one, in the same order they were put in. If the obtained <key> is NULL, the end of the list was reached. read-fifo starts with the first element put in, and moves forward from there, unless rewind-fifo is called, which positions back to the first one.
Examples
In this example, a FIFO list is created, and two key/value pairs added. They are then retrieved in a loop and printed out (twice with rewind), and then the list is purged:
// Create a list
new-fifo mylist

// Add data to the list
write-fifo mylist key "key1" value "value1"
write-fifo mylist key "some2" value "other2"

while (1) {
    // Get data from the list
    read-fifo mylist key define k value define v

    // Check if no more data
    if (k == NULL) {
        break;
    }

    @Obtained key <<p-out k>> with value <<p-out v>>
}

// Go through the list again, use rewind-fifo for that
rewind-fifo mylist

while (1) {
    read-fifo mylist key define k value define v
    if (k == NULL) {
        break;
    }
    @Again obtained key <<p-out k>> with value <<p-out v>>
}

purge-fifo mylist

See also
FIFO ( new-fifo   purge-fifo   read-fifo   rewind-fifo   write-fifo  )  SEE ALL (documentation)


Copyright (c) 2017-2023 Dasoftver LLC