> For the complete documentation index, see [llms.txt](https://tomelam.gitbook.io/mashweb/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tomelam.gitbook.io/mashweb/part-3-the-key-to-zen-a-nano-framework-for-sequential-programming/synchronization-of-javascript-events.md).

# Synchronization of JavaScript Events

To bring all user and Ajax interaction under the control of a single, sequential process, the main thread of execution must wait for the execution of at least one JavaScript event handler.

Here is a simple program that illustrates the funnelling of all asynchronous JavaScript events into a single queue:

```
(load "mini-framework.scm")
(define (test)
  (with-handlers ((click-handler "#div1")
                  (click-handler "#div2")
                  (keydown-handler "#button1")
                  (keydown-handler "#button2")
                  (timeout-handler test-timeout 10000))
                 (display (get-input))
                 (display (get-input))
                 (display (get-input))
                 (display (get-input))
                 (display (get-input)))
  (display "Test finished."))
  
(reset (test))
```

The program is described at <https://doc.mashweb.club/experiments/seq_webapp_biwascheme/> .
