How to program a daemon?

A daemon is a process that runs in the background, and in the context of thox, usually organizes its work around procedure calls from clients. Daemons can be many things, even a counter if you like (think visit counters on websites from the 2000s), but most are resource management processes borrowing the “one daemon, one resource” philosophy from UNIX.

In order to make a daemon, the easiest way is probably to use the daemon library by requiring it. The result of this requirement process is an object which you can use to bind functions and run the call dispatcher.

A simple example of using this module is the following:

local daemon = require "daemon" = function (request, arg1, arg2)
        local time = rpc.clock()
        return "" .. arg1 .. " - " .. time .. " - " .. arg2, time

daemon.rpc.hello.universe = function (request, number_arg)
        return number_arg + 5