Several improvements and unit test.

This version now does its own processing of lines, in a way that
guarantees that each line will be processed by the full chain
of promises before the next line is read. The output is therefore
deterministic even when input is piped from a file.

One unit test is provided, which demonstrates that the input
script can return a promise, in which case the script interpreter
waits until the promise is fulfilled in order to print the result.