Daerth, by
PYK, is a multi-threaded system providing queues and transport who consume from one queue and feed another.
Description edit
Each
queue is in its own thread. Each
transport is given a
source queue to consume from and a
destination queue to feed. Queue operations
block until successful. Blocking is implemented via
coroutines: Any script performing queue operations must run in a coroutine context, and every queue operation suspends the coroutine which is then woken up later by an acknowledgement from the queue. When a queue is empty and there are no more feeders,
take returns a code of
break. Worker threads end automatically. Queues are deleted by the user.
A transport typically calls
daerth deliver in a loop which is broken when the queue is exhausted.
Synopsis edit
- daerth queue .spawn cmdname
- Create a new queue.
- daerth pipeline name producers ?transports ...?
- A produer is produced for each item in producers and that item is passed to the producer as its work argument. A transport is produced for each item in each transports list, and that item becomes its args list. Queues are created between each group of producers and transports. A new command named name is created. Each time it is called it returns one result from the final queue, or if the pipeline is exhausted it returns a code of break and deletes itself and all relevant queues.
- daerth producer queue work
- Create a new producer to feed a queue. work is a list of arguments to pass to apply, and when it is applied the fully-qualified name of the command for the daerth system is passed as the last argument.
- daerth transport source dest args
- source is the thread for the source queue, dest is the thread for the destination queue, args is a list of arguments to apply, as described for daerth producer is a list of arguments to apply. The name of the transport command is passed to this procedure as the first argument.
Transport commands edit
- take
- Take one item from the source queue. Returns the item, or -code break if the queue is empty.
- deliver
- Deliver a value to the destination queue and take one item from the source queue.
Queue commands edit
- init
- Initialize the queue.
- exit
- Finalize the queue and release the thread for it.
Station commands edit
- count
- The number of transports to create.
- transport
- A list whose items are passed as the arguments to transport.
Examples edit
See the
test suite.