-
-
Notifications
You must be signed in to change notification settings - Fork 1
Description
The examples are used as tests to validate the fork/join pattern, but they can be made more didactic for Pony learners.
For instance, all examples output the completion of the join by writing the result in the Collector
finish
function, but frequently one will need to get that result into the actor that initiated the fork/join process. So instead of printing the output in the Collector
, having the example outputting the result in Main
actor would show how the result can be sent back to the initiator.
Also, inserting Debug
with digestof this
into the functions of the three classes *Worker
, *Generator
and *Collector
of the examples would show the users who run those examples in debug mode how the work is split between multiple actors and get collected at the end.
Sample for process-array.pony
class Adder is fj.Worker[Array[U8] iso, USize]
var _working_set: Array[U8] = _working_set.create()
fun ref receive(work_set: Array[U8] iso) =>
Debug("Adder #" + (digestof this).string() + " receiving work to do")
_working_set = consume work_set
fun ref process(runner: fj.WorkerRunner[Array[U8] iso, USize] ref) =>
Debug("Adder #" + (digestof this).string() + " doing work")
var total: USize = 0
for i in _working_set.values() do
total = total + i.usize()
end
Debug("Adder #" + (digestof this).string() + " completed work")
runner.deliver(total)
Last, adding how to use the word-count.pony
example in case of launch error is more user friendly than reporting an error:
env.exitcode(-1)
env.err.print("Error during setup.")
env.err.print("Usage: word-count <filename>")