Examples

The Canary

Since the script execution and loading is done dynamically, it might be a good idea a canary to find out whether the distributed system is properly online.

The canary is a signal with a starter node that sequentially visit any path that might be used by other scripts, and then returns back to the starter node. This might be done once or with a given interval depending on the need of the system. It might also be useful to include timestamp to the signal so that it is possible to measure the round trip time, somewhat accurately.

Say for instance that we have a couple of nodes with the names: Control, NodeA, NodeB, NodeC. The canary might then be implemented scriptwise such as:

In this case the CanaryEnd method also takes a string representing which path that is measured. This examples also only covers the pathes ABC and CBA, and not BAC for instance. If the other combinations of traversal is also used, those too should be tested.

It is noteworthy that it would be a could idea to clean up the interval set by the CanaryStart functions, since it would keep going even though the script might be shut down. This is done through the context this and the event onstop, which fires once the script stops.

Osc

Or any other message passing protocol.

Say for instance we have a setup with alot of different multimedia devices that we would like to use as one, and they all talk OSC. So the baseline functionality is that each node in the network has at least two functions: SendOSC(address, value) and ReceiveOSC(address) => (time, value).

The basic scenario would be that we listen to OSC from one node and transfer a corresponsing signal in another.

And let’s say that /beat1 fires 60 times per minute and /beat2 fires 120 times per minute. First of, continue would be set to the last signal callback. Which would probably be /beat2 since it fires much faster. So /dashboard/bpm1 might never be set. But the returned bpm value from PerMinute would also be wrong. It would likely be around 60 + 120. One way to fix this would be to add an identifier to each signal.

Cross Protocol

As we saw in the example above, it is fairly straight forward to build signals between nodes which in turn communicates something outside of Func.is. But it is perhaps more interesting to note that it is as easy to facilitate communication between different protocols. To continue with the example above, lets extend it so that the light fixtures are controlled by DMX.

There is obviously issues with data format transformation inbetween protocols, but that can be overcome by implementing a general data format which exists inside the Func.is domain and simply make sure that those functions which extend outside of this domain properly handle the corresponding transformation.

HTTP API

Let’s see if we can make a proper HTTP api for our little sound and lights setup. Let’s open up two addresses for turning a light on and off.

Now this is of course the very basic kind of http listener. For instance it would be extended to allow multiple scripts to listen to the same address. Or we could do regex matching on the http request url, or support various HTTP methods and so on.