The program is written in monadic style, but it is based on the Continuation Monad.
When started, the
newDate.getTime(). Explicit delays are used to yield control to other threads.
The figure below shows contents of the web browser window after running the test program above. Actual timeout value is of course different in each run of the program.
Fig. 1: Web browser window showing output of the test program
Try it out
The compiled HTML page of this demo program is accessible at: