Qu

push

Builtin index · Collections & strings

result = push(q, x) / pop(q) / peek(q)

Input: q, x · Output: result

What it is

On a fifo handle q: push(q, x) adds x at the back (returns Nothing); pop(q) removes and returns the front element; peek(q) looks at it without removing. pop on an empty FIFO is an error. On a queue() — the job queue — push(q, "fname") enqueues a function you defined instead (a Str naming it, not a value).

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = push(q, x) / pop(q) / peek(q)
q —peek(q) looks at it without removing.
x —On a fifo handle q: push(q, x) adds x at the back (returns Nothing).
result —
Returns the front element itself from pop/peek, whatever type was pushed; push hands back no value.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

square(x) := x * x
pool workers with cpu=2
end pool
q = queue()
q.push("square", 3)
print(run q on workers)   # (9)

output
(9)

from concurrency

square(x) := x * x

pool workers with cpu=4
end pool

q = queue()
for i in 0 to 4
    q.push("square", i)
end for

results = run q on workers
print(results)              # (0, 1, 4, 9, 16)

output
(0, 1, 4, 9, 16)

from concurrency

function square(x)
    return x * x
end function

pool workers with cpu=4
    policy = round_robin        # or priority | fair | affinity

    on full = queue             # or reject | spill_to(cpu)

end pool

q = queue()
for i in 0 to 9
    q.push("square", i)         # enqueue a deferred call by name + args

end for

results = run q on workers
print(results)

from tour

square(x) := x * x                    # still needed locally: `run` validates

                                       # every queued function name against

                                       # the CALLING script's own functions

                                       # before dispatching anything, even a

                                       # job that will actually run remotely


pool workers with cpu=2, remote=("192.168.1.50:9000", "192.168.1.51:9000")
end pool

q = queue()
for i in 0 to 9
    q.push("square", i)
end for

results = run q on workers            # some jobs run locally, some remote —

                                       # one ordered List either way

from tour

See also

pop, peek — documented in the same entry.